Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SET_WALLBOX_START and SET_WALLBOX_STOP? #58

Open
othorg opened this issue Mar 6, 2022 · 13 comments
Open

SET_WALLBOX_START and SET_WALLBOX_STOP? #58

othorg opened this issue Mar 6, 2022 · 13 comments

Comments

@othorg
Copy link

othorg commented Mar 6, 2022

Hi,

do you think, it's possible to implement a simple SET function for the E3DC Wallbox smart connect for starting and stopping the charging-process?

In the S10 Webportal can i see in the wallbox.js script this code for stopping charging:
var barry = new Uint8Array(6); barry[0] = 0;barry[1] = 0;barry[2] = 0;barry[3] = 0;barry[4] = 1;barry[5] = 0; return dataProxy.rscp.request( dataProxy.rscp.containerFactory("WB_REQ_DATA", dataProxy.rscp.dataFactory("WB_INDEX","UChar8",currentWallBox), dataProxy.rscp.containerFactory("WB_REQ_SET_EXTERN", dataProxy.rscp.dataFactory("WB_EXTERN_DATA","ByteArray",barry), dataProxy.rscp.dataFactory("WB_EXTERN_DATA_LEN","UChar8",6)

and for starting:

var barry = new Uint8Array(6); barry[0] = 0;barry[1] = 0;barry[2] = 0;barry[3] = value;barry[4] = 0;barry[5] = 0; return dataProxy.rscp.request( dataProxy.rscp.containerFactory("WB_REQ_DATA", dataProxy.rscp.dataFactory("WB_INDEX","UChar8",parseInt(currentWallBox)), dataProxy.rscp.containerFactory("WB_REQ_SET_EXTERN", dataProxy.rscp.dataFactory("WB_EXTERN_DATA","ByteArray",barry), dataProxy.rscp.dataFactory("WB_EXTERN_DATA_LEN","UChar8",6)

Or do you think, it's possible to implement the whole function of the wallbox.js?

Thanks in advance

@vchrisb
Copy link
Collaborator

vchrisb commented Mar 6, 2022

This should be possible, but not using wallbox.js, but rather implementing it similar to other methods in _e3dc.py.
e.g. https://github.com/fsantini/python-e3dc/blob/master/e3dc/_e3dc.py#L1840

The tags can be found e.g. here: https://github.com/fsantini/python-e3dc/blob/master/e3dc/_rscpTags.py#L1244
and testing can be done using e3dc.sendRequest()

I don't have a wallbox and hence can't test it.
There are other folks active in this project with a wallbox that might be open to collaborate, like @mdhom.
Feel free to implement this and open a PR.

@mdhom
Copy link
Contributor

mdhom commented Mar 6, 2022

Sounds interesting, I could have look at it maybe tonight.

@mdhom
Copy link
Contributor

mdhom commented Mar 6, 2022

First I implemented the WB_REQ_DATA to see if I can actually see the live wallbox data, that works. Then I implemented the method which is called setStopCharging in wallbox.js, but that actually looks more like a toggle charging functionality, which matches my observation that there is no setStartCharging function in JS. It's a pity that the bytearray I have to send is just magic, I don't know if there could be any other byte-array I could send to definitely start or stop the wallbox.

@othorg you could give it a try with my current branch here:
https://github.com/mdhom/python-e3dc/tree/wallbox-rscp

Things I need / want to do:

  • Read current state of sun mode
  • Activate / deactivate sun mode
  • Read current state of one phased charging
  • Read current phases setting
  • Read max charging current
  • Read Schuko state
  • Set Schuko state
  • Find out what SOC means in this context (does not match what is shown in my cars display)
  • Find out what energy measurements refer to (currently looks like the current months sum)
  • There is some code that switches on a wallbox type, but takes a WALLBOX_ARRAY from somewhere, can't find the source of this...

@mdhom
Copy link
Contributor

mdhom commented Mar 6, 2022

@othorg the code you posted for starting charging seems to be for switching between one and three phased charging

@othorg
Copy link
Author

othorg commented Mar 6, 2022

Hi,
you're fast @mdhom ;-)

Funny.... My code is near the same... i played the last two hours...

def set_sun_mode(self, enable, keepAlive=False):
            """Setting the Wallbox Sun mode function via rscp protocol locally.

            Args:
                enable (bool): True/False
                keepAlive (Optional[bool]): True to keep connection alive

            Returns:
                0 if success
                -1 if error
            """
            
            barry_on = bytearray([1,0,0,0,0,0])
            barry_off = bytearray([2,0,0,0,0,0])

            if enable:
                #pprint(barry_on)
                res = self.sendRequest(
                    (
                        "WB_REQ_DATA",
                        "Container",
                        [
                            ("WB_INDEX", "UChar8", 0),
                            ("WB_REQ_SET_EXTERN", "Container",
                            [
                                ("WB_EXTERN_DATA", "ByteArray", barry_on), 
                                ("WB_EXTERN_DATA_LEN", "UChar8", 6),
                            ])
                        ],
                    ),
                    keepAlive=keepAlive,
                )
                pprint(res)
            
            else:
                 res = self.sendRequest(
                    (
                        "WB_REQ_DATA",
                        "Container",
                        [
                            ("WB_INDEX", "UChar8", 0),
                            ("WB_REQ_SET_EXTERN", "Container",
                            [
                                ("WB_EXTERN_DATA", "ByteArray", barry_off), 
                                ("WB_EXTERN_DATA_LEN", "UChar8", 6),
                            ])
                        ],
                    ),
                        keepAlive=keepAlive,
                )
            pprint(res)

@othorg
Copy link
Author

othorg commented Mar 6, 2022

I will connect my car again asap. After this, i will inspect the start/stop Button in Webportal. my function above is working and switch the sun mode on/off.

@mdhom
Copy link
Contributor

mdhom commented Mar 6, 2022

yes, setting sunmode works perfectly, is also implemented in my code. just starting and stopping charging is somehow strange...

@mdhom
Copy link
Contributor

mdhom commented Mar 6, 2022

do you have a Schuko on your wallbox to test that behavior? I implemented reading out its state and setting it too, but nothing happens here, I think because I don't have a Schuko on my wallbox
Pushed some changes again...

@othorg
Copy link
Author

othorg commented Mar 6, 2022

No Sorry i don't have a Schuko... but E3DC have two kinds of WB's. What do you have?
I have the newer one "Smart Connect" 22KW with 3Phases and fixed cable... And for me it looks like, that the start behavior is a toggle function of setStopCharging()?

self.stopCharging = function (){
		if (window.OWNER !==3) {
      language.addModule(24).then(function(){
          AXConfirm(language.gE('346M24'),function yes(){
            setStopCharging();
          }, function no(){
            // do nothing
          });
      });	
			
		} 
	};
	self.restartCharging = function (){
		if (window.OWNER !==3) setStopCharging();
		
	};
	
	
}

function setStopCharging(){
	if (window.OWNER ===3) {
		return;
	}
	if (!inUpdate) {
		var barry = new Uint8Array(6);
		//barry[0] = 0;barry[1] = 0;barry[2] = 0;barry[3] = 0;barry[4] = 0;barry[5] = 1;
		barry[0] = 0;barry[1] = 0;barry[2] = 0;barry[3] = 0;barry[4] = 1;barry[5] = 0;

	
		return dataProxy.rscp.request(
			dataProxy.rscp.containerFactory("WB_REQ_DATA",
				dataProxy.rscp.dataFactory("WB_INDEX","UChar8",currentWallBox),
				dataProxy.rscp.containerFactory("WB_REQ_SET_EXTERN",
					dataProxy.rscp.dataFactory("WB_EXTERN_DATA","ByteArray",barry),
					dataProxy.rscp.dataFactory("WB_EXTERN_DATA_LEN","UChar8",6)
				)
			)
		).then(function(data){
			// if(typeof data[0].value.WB_REQ_SET_EXTERN !== "undefined" && data[0].value.WB_REQ_SET_EXTERN.type === "Error"){
			// 	return Promise.reject();
			// }
			// else {
			// 	return Promise.resolve();
			// }
		}).catch(function(err){
			console.error(err);
			// return Promise.reject();
		});
	}
	  

restartcharging() is only available if sunmode is switched off or enough PV-Power is availible....

@mdhom
Copy link
Contributor

mdhom commented Mar 6, 2022

I've got the E3/DC Wallbox Easy connect flex (no fixed cable). So do you also think we should call the method "toggle"?

@mdhom
Copy link
Contributor

mdhom commented Mar 6, 2022

I created a draft PR: #59
I think we could discuss the implementation details there.

@Balu-78
Copy link

Balu-78 commented Oct 29, 2023

I like what you are planning to implement.
I was scanning the repo, as I wanted to change the charging priorioty from wallbox to battery and back
on certain conditions... let's say when the battery of the e3dc system reaches let's say 80% set the charging priority to wallbox.
Do yo think this would be achievable as well in general ?

@klepptor
Copy link

Keep up your great work here!

Looking forward to seeing this implemented for all the projects relying on this library as it's necessary to get the most out of dynamic power tariffs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants