-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add support for energy sensor on S31 #4
base: master
Are you sure you want to change the base?
Conversation
Add support for S31 Sensor
Hmm. Found a bug in which the switch doesn’t always respond to MQTT commands. I’ll fix this during the week |
Ok so I checked closer and my PR didnt cause instability with Homemate.. My test box did ;) It's all good now. One thing to note is that I rarely see energy update events on the "wire"; however, when the homemate app is open, it seems to send one every few seconds .- so my guess is that there is a cmd to send to tell it to send them; however, I can't get the stream_decode.py to work. I have the 16 character key, but I always get the complaint about the keysize.. any feedback?
|
At a guess, you've either got a trailing new line character at the end of the Try something like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some notes; generally, good job understanding my code! I know its a bit of a mess
src/homemate_bridge/cli.py
Outdated
# Close the connection if the switch doesn't send anything in 30 minutes | ||
# See !1 | ||
self.request.settimeout(60 * 30) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish I had a good reason.. Adding it back in.
src/homemate_bridge/cli.py
Outdated
if 'name' not in self.settings: | ||
self.settings['name'] = "Homemate Switch " + localip | ||
|
||
logger.debug("Device settings: {}".format(self.settings)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove? This is important for my use-case; as I run my bridge in a Kubernetes cluster, so the connections to the bridge are NATed, and appear to all come from the same IP. I use the IP that the device itself reports as an ID so I can tell them apart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah.
src/homemate_bridge/cli.py
Outdated
def format_response(self, packet, response_payload): | ||
response_payload['cmd'] = packet.json_payload['cmd'] | ||
response_payload['serial'] = packet.json_payload['serial'] | ||
response_payload['status'] = 0 | ||
|
||
# if 'energy' in packet.json_payload: | ||
#response_payload['energy'] = packet.json_payload['energy'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Done
@@ -300,16 +305,19 @@ def handle(self): | |||
self._mqtt_switch = HomemateSwitch( | |||
self, | |||
name=self.settings['name'], | |||
entity_id=self.entity_id | |||
entity_id=self.client_address[0].replace('.', '_') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
src/homemate_bridge/cli.py
Outdated
if self._mqtt_sensor is None: | ||
self._mqtt_sensor = HomematePowerSensor(self, | ||
name=self.settings['name'], | ||
entity_id=self.client_address[0].replace('.', '_') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use self.entity_id
@property | ||
def cmd_handlers(self): | ||
return { | ||
0: self.handle_hello, | ||
32: self.handle_heartbeat, | ||
42: self.handle_state_update, | ||
6: self.handle_handshake | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Device handshakes need an ACK at the minimum otherwise they disconnect after awhile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/homemate_bridge/cli.py
Outdated
|
||
return self.handle_default(packet) | ||
|
||
def handle_energy_update(self, packet): | ||
if 'energy' in packet.json_payload: | ||
self.energy = packet.json_payload['energy'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why track the current energy reading as an instance variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought it was a bit cleaner... any reason not too?
Thanks! I will clean this all up and try again soon! |
For the key, I get b'khggd54865.....' w/o a new line at the end... I have tried it in that format and without the b''.. No luck. W/o the b'' it is 16 alphanumerics. Oh and to get the key, I'm doing |
@insertjokehere - any idea about the key? |
@boojew I've updated |
No love...
Keys.json looks like this: I should also mention, stream.yaml is your example file - not one I generated. In case you have 5 minutes, I'm also including my pcap in case you could decode and put in back here - just so I can continue testing the energy capture. Thanks! |
I've updated |
Looks like it's cmd 128 that tells the switch to respond with the power related stuff. |
Get power output
I was able to get this to work. I have commited some code in https://github.com/boojew/homemate-bridge/blob/master/src/homemate_bridge/cli.py and I will tune it over the next few days. If anyone wants to try it, check out https://hub.docker.com/r/boojew/homemate-bridge. Be sure to pass the pass the keyfile as a volume or env and pass the host as the env variable MQTT_HOST |
@boojew hows the tuning going? |
@boojew I'm getting this error when I attempt to use your fork of this plugin:
|
what units is the energy variable in? Kwh? |
I know this is ancient, but I just picked up a bunch of S31 switches and was hoping to get 'em integrated into my home assistant instance. Got my MQTT broker running in home assistant, and am able to connect to it from other devices on the network. Got my "PK" encryption key from the kepler.apk. Set up a simple docker-compose in my portainer instance:
But unfortunately I'm getting this error: Any ideas what might be going awry here? ':D I'm able to ping the MQTT broker from other containers within my portainer instance so it should be able to see the 0.115 IP... are there other environment variables I'm missing here? I've got an account configured in home assistant to access the MQTT broker, how would I go about configuring that for this bridge? |
@Eamourinho - wow, I'm glad that people are still finding this useful. I don't really remember how any of this works, but two guesses:
While I'm here, @boojew sorry you got such a terse code review back in the day, thanks for putting in the effort to put your changes up for others to use. |
Requires insertjokehere/python-hassdevice#1