TP-Link smart plug HS100/HS110

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

Hi @jaaap, it looks very close, so I'm suspecting a syntax error, possibly with the Python version.

The error is happening after the lines (around 157 and 177)

Code: Select all

logger.debug("URL: {}".format(full_url))
as we see from the debug logging that the URL looks correct. And you have confirmed it is correct by pasting the URL into a browser and it updates Domoticz.

We don't get the log for the following lines of code

Code: Select all

logger.debug("Logger response: {}".format(result))
so the 'error' occurs somewhere in between. However, the confusing part is that the error is 'None', so I'm not sure an error has actually occurred.

Looking at the Python docs for urllib.request, I see this:
Changed in version 3.6: Do not raise an error if the Content-Length has not been provided and data is neither None nor a bytes object. Fall back to use chunked transfer encoding instead.
https://docs.python.org/3/library/urllib.request.html

It is a little above my understanding, but can you try replacing

Code: Select all

req = urllib.request.Request(full_url)
with

Code: Select all

req = urllib.request.Request(full_url, data=None)
in the two places where it is used (around lines 157 and 179)?
jaaap
Posts: 59
Joined: Sunday 28 July 2019 22:59
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by jaaap »

@ajay100 Thank you for your time. I appreciate it very much!

I tried replacing the lines, however, no luck. When executing from the command line is gives the same output in the log file. See here:

Code: Select all

2019-09-23 15:48:23,966:__main__:INFO:hs110-3 version 3.5 has started...
2019-09-23 15:48:23,990:__main__:DEBUG:Command: {"system":{"set_relay_state":{"state":1}}}
2019-09-23 15:48:23,990:__main__:DEBUG:Encoded string: b'{"system":{"set_relay_state":{"state":1}}}'
2019-09-23 15:48:23,991:__main__:DEBUG:Encrypted Command: b'\x00\x00\x00*\xd0\xf2\x81\xf8\x8b\xff\x9a\xf7\xd5\xef\x94\xb6\xc5\xa0\xd4\x8b\xf9\x9c\xf0\x91\xe8\xb7\xc4\xb0\xd1\xa5\xc0\xe2\xd8\xa3\x81\xf2\x86\xe7\x93\xf6\xd4\xee\xdf\xa2\xdf\xa2'
2019-09-23 15:48:23,991:__main__:DEBUG:Encoded string: b'{"system":{"set_relay_state":{"state":1}}}'
2019-09-23 15:48:24,002:__main__:DEBUG:data: b'\x00\x00\x00-\xd0\xf2\x81\xf8\x8b\xff\x9a\xf7\xd5\xef\x94\xb6\xc5\xa0\xd4\x8b\xf9\x9c\xf0\x91\xe8\xb7\xc4\xb0\xd1\xa5\xc0\xe2\xd8\xa3\x81\xe4\x96\xe4\xbb\xd8\xb7\xd3\xb6\x94\xae\x9e\xe3\x9e\xe3'
2019-09-23 15:49:43,308:__main__:INFO:hs110-3 version 3.5 has started...
2019-09-23 15:49:43,317:__main__:DEBUG:Command: {"system":{"set_relay_state":{"state":0}}}
2019-09-23 15:49:43,318:__main__:DEBUG:Encoded string: b'{"system":{"set_relay_state":{"state":0}}}'
2019-09-23 15:49:43,318:__main__:DEBUG:Encrypted Command: b'\x00\x00\x00*\xd0\xf2\x81\xf8\x8b\xff\x9a\xf7\xd5\xef\x94\xb6\xc5\xa0\xd4\x8b\xf9\x9c\xf0\x91\xe8\xb7\xc4\xb0\xd1\xa5\xc0\xe2\xd8\xa3\x81\xf2\x86\xe7\x93\xf6\xd4\xee\xde\xa3\xde\xa3'
2019-09-23 15:49:43,319:__main__:DEBUG:Encoded string: b'{"system":{"set_relay_state":{"state":0}}}'
2019-09-23 15:49:43,433:__main__:DEBUG:data: b'\x00\x00\x00-\xd0\xf2\x81\xf8\x8b\xff\x9a\xf7\xd5\xef\x94\xb6\xc5\xa0\xd4\x8b\xf9\x9c\xf0\x91\xe8\xb7\xc4\xb0\xd1\xa5\xc0\xe2\xd8\xa3\x81\xe4\x96\xe4\xbb\xd8\xb7\xd3\xb6\x94\xae\x9e\xe3\x9e\xe3'
2019-09-23 15:49:48,968:__main__:INFO:hs110-3 version 3.5 has started...
2019-09-23 15:49:48,979:__main__:DEBUG:Command: {"emeter":{"get_realtime":{}}}
2019-09-23 15:49:48,980:__main__:DEBUG:Encoded string: b'{"emeter":{"get_realtime":{}}}'
2019-09-23 15:49:48,980:__main__:DEBUG:Encrypted Command: b'\x00\x00\x00\x1e\xd0\xf2\x97\xfa\x9f\xeb\x8e\xfc\xde\xe4\x9f\xbd\xda\xbf\xcb\x94\xe6\x83\xe2\x8e\xfa\x93\xfe\x9b\xb9\x83\xf8\x85\xf8\x85'
2019-09-23 15:49:48,981:__main__:DEBUG:Encoded string: b'{"emeter":{"get_realtime":{}}}'
2019-09-23 15:49:49,088:__main__:DEBUG:data: b'\x00\x00\x00h\xd0\xf2\x97\xfa\x9f\xeb\x8e\xfc\xde\xe4\x9f\xbd\xda\xbf\xcb\x94\xe6\x83\xe2\x8e\xfa\x93\xfe\x9b\xb9\x83\xf8\xda\xac\xc3\xaf\xdb\xba\xdd\xb8\xe7\x8a\xfc\xde\xe4\xd6\xe5\xd0\xe9\xd1\xe2\xce\xec\x8f\xfa\x88\xfa\x9f\xf1\x85\xda\xb7\xd6\xf4\xce\xff\xc9\xe5\xc7\xb7\xd8\xaf\xca\xb8\xe7\x8a\xfd\xdf\xe5\xd5\xf9\xdb\xaf\xc0\xb4\xd5\xb9\xe6\x91\xf9\xdb\xe1\xd8\xf4\xd6\xb3\xc1\xb3\xec\x8f\xe0\x84\xe1\xc3\xf9\xc9\xb4\xc9\xb4'
2019-09-23 15:49:49,088:__main__:DEBUG:Sent:     {"emeter":{"get_realtime":{}}}
2019-09-23 15:49:49,089:__main__:DEBUG:Received: {"emeter":{"get_realtime":{"voltage_mv":235983,"current_ma":16,"power_mw":0,"total_wh":9,"err_code":0}}}
2019-09-23 15:49:49,089:__main__:DEBUG:json_data: {'emeter': {'get_realtime': {'current_ma': 16, 'err_code': 0, 'voltage_mv': 235983, 'power_mw': 0, 'total_wh': 9}}}
2019-09-23 15:49:49,090:__main__:DEBUG:IDX: 37, Item: voltage, Value: 235.98
2019-09-23 15:49:49,090:__main__:DEBUG:URL: http://192.168.2.1:8084/json.htm?type=command&param=udevice&nvalue=0&idx=37&svalue=235.98
2019-09-23 15:49:49,113:__main__:ERROR:HTTP error(None): None
2019-09-23 15:49:49,116:__main__:DEBUG:Command: {"system":{"get_sysinfo":{}}}
2019-09-23 15:49:49,117:__main__:DEBUG:Encoded string: b'{"system":{"get_sysinfo":{}}}'
2019-09-23 15:49:49,117:__main__:DEBUG:Encrypted Command: b'\x00\x00\x00\x1d\xd0\xf2\x81\xf8\x8b\xff\x9a\xf7\xd5\xef\x94\xb6\xd1\xb4\xc0\x9f\xec\x95\xe6\x8f\xe1\x87\xe8\xca\xf0\x8b\xf6\x8b\xf6'
2019-09-23 15:49:49,118:__main__:DEBUG:Encoded string: b'{"system":{"get_sysinfo":{}}}'
2019-09-23 15:49:49,198:__main__:DEBUG:data: b'\x00\x00\x02b\xd0\xf2\x81\xf8\x8b\xff\x9a\xf7\xd5\xef\x94\xb6\xd1\xb4\xc0\x9f\xec\x95\xe6\x8f\xe1\x87\xe8\xca\xf0\x8b\xa9\xda\xad\xf2\x84\xe1\x93\xb1\x8b\xa9\x98\xb6\x83\xad\x99\xb9\xfb\x8e\xe7\x8b\xef\xcf\xfe\xc6\xf6\xce\xff\xca\xea\xb8\xdd\xb1\x9f\xae\x9c\xad\x99\xad\x9d\xbf\x93\xb1\xd9\xae\xf1\x87\xe2\x90\xb2\x88\xaa\x98\xb6\x86\xa4\x88\xaa\xde\xa7\xd7\xb2\x90\xaa\x88\xc1\x8e\xda\xf4\xa7\xea\xab\xf9\xad\xfd\xb1\xe4\xa3\xf0\xa7\xee\xba\xf9\xb1\x93\xbf\x9d\xf0\x9f\xfb\x9e\xf2\xd0\xea\xc8\x80\xd3\xe2\xd3\xe3\xcb\x8e\xdb\xf2\xd0\xfc\xde\xb3\xd2\xb1\x93\xa9\x8b\xb2\x8a\xb0\xf4\xb5\x8f\xcc\xf8\xc2\xf4\xb5\x8f\xb8\xf9\xc3\xf5\xb3\x91\xbd\x9f\xfb\x9e\xe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\x89\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x9b\xab\x89\xa5\x87\xe3\x86\xf0\x99\xfa\x9f\xd6\xb2\x90\xaa\x88\xb0\x80\xb0\x86\xc7\x82\xbb\xfd\xcb\xf8\xce\x8c\xc8\x8a\xc9\xfb\xcb\xf2\xb0\x81\xb8\xf9\xb8\xfa\xcc\xf8\xca\xf2\xc5\xf2\xc4\xf7\xc6\x84\xc5\x84\xc6\xf4\xb5\x8c\xae\x82\xa0\xcf\xaa\xc7\x8e\xea\xc8\xf2\xd0\xe1\xd8\xe1\xd9\x98\xa9\x9d\xd9\x98\xd9\xe1\xd7\x92\xa6\xe3\xd3\xe3\xd2\x94\xd0\xe7\xa4\xe5\xa3\x97\xa5\x9d\xab\x93\xd1\xe4\xa1\x83\xaf\x8d\xe3\x86\xfe\x8a\xd5\xb4\xd7\xa3\xca\xa5\xcb\xe9\xd3\xa8\x8a\xfe\x87\xf7\x92\xb0\x8a\xa7\x96\xeb\xc7\xe5\x80\xf2\x80\xdf\xbc\xd3\xb7\xd2\xf0\xca\xfa\x87\xfa\x87'
2019-09-23 15:49:49,199:__main__:DEBUG:Sent:     {"system":{"get_sysinfo":{}}}
2019-09-23 15:49:49,199:__main__:DEBUG:Received: {"system":{"get_sysinfo":{"sw_ver":"1.5.4 Build 180815 Rel.121440","hw_ver":"2.0","type":"IOT.SMARTPLUGSWITCH","model":"HS110(EU)","mac":"98:DA:C4:6A:7A:6F","dev_name":"Smart Wi-Fi Plug With Energy Monitoring","alias":"wasmachine-meter","relay_state":0,"on_time":0,"active_mode":"none","feature":"TIM:ENE","updating":0,"icon_hash":"","rssi":-56,"led_off":0,"longitude_i":0,"latitude_i":0,"hwId":"044A516EE63C875F9458DA25C2CCC5A0","fwId":"00000000000000000000000000000000","deviceId":"8006AE9F636BDBC209B19AAB642877631BAAB2A9","oemId":"1998A14DAA86E4E001FD7CAF42868B5E","next_action":{"type":-1},"err_code":0}}}
2019-09-23 15:49:49,200:__main__:DEBUG:json_data: {'system': {'get_sysinfo': {'type': 'IOT.SMARTPLUGSWITCH', 'rssi': -56, 'relay_state': 0, 'dev_name': 'Smart Wi-Fi Plug With Energy Monitoring', 'err_code': 0, 'hwId': '044A516EE63C875F9458DA25C2CCC5A0', 'model': 'HS110(EU)', 'on_time': 0, 'oemId': '1998A14DAA86E4E001FD7CAF42868B5E', 'hw_ver': '2.0', 'sw_ver': '1.5.4 Build 180815 Rel.121440', 'latitude_i': 0, 'alias': 'wasmachine-meter', 'led_off': 0, 'updating': 0, 'next_action': {'type': -1}, 'active_mode': 'none', 'longitude_i': 0, 'mac': '98:DA:C4:6A:7A:6F', 'feature': 'TIM:ENE', 'deviceId': '8006AE9F636BDBC209B19AAB642877631BAAB2A9', 'icon_hash': '', 'fwId': '00000000000000000000000000000000'}}}
2019-09-23 15:49:49,200:__main__:DEBUG:URL: http://192.168.2.1:8084/json.htm?type=command&param=udevice&idx=13&nvalue=0
2019-09-23 15:49:49,203:__main__:ERROR:HTTP error(None): None
2019-09-23 15:50:04,221:__main__:DEBUG:Command: {"emeter":{"get_realtime":{}}}
2019-09-23 15:50:04,221:__main__:DEBUG:Encoded string: b'{"emeter":{"get_realtime":{}}}'
2019-09-23 15:50:04,222:__main__:DEBUG:Encrypted Command: b'\x00\x00\x00\x1e\xd0\xf2\x97\xfa\x9f\xeb\x8e\xfc\xde\xe4\x9f\xbd\xda\xbf\xcb\x94\xe6\x83\xe2\x8e\xfa\x93\xfe\x9b\xb9\x83\xf8\x85\xf8\x85'
2019-09-23 15:50:04,222:__main__:DEBUG:Encoded string: b'{"emeter":{"get_realtime":{}}}'
2019-09-23 15:50:04,328:__main__:DEBUG:data: b'\x00\x00\x00h\xd0\xf2\x97\xfa\x9f\xeb\x8e\xfc\xde\xe4\x9f\xbd\xda\xbf\xcb\x94\xe6\x83\xe2\x8e\xfa\x93\xfe\x9b\xb9\x83\xf8\xda\xac\xc3\xaf\xdb\xba\xdd\xb8\xe7\x8a\xfc\xde\xe4\xd6\xe5\xd0\xe5\xd6\xe1\xcd\xef\x8c\xf9\x8b\xf9\x9c\xf2\x86\xd9\xb4\xd5\xf7\xcd\xfc\xca\xe6\xc4\xb4\xdb\xac\xc9\xbb\xe4\x89\xfe\xdc\xe6\xd6\xfa\xd8\xac\xc3\xb7\xd6\xba\xe5\x92\xfa\xd8\xe2\xdb\xf7\xd5\xb0\xc2\xb0\xef\x8c\xe3\x87\xe2\xc0\xfa\xca\xb7\xca\xb7'
2019-09-23 15:50:04,329:__main__:DEBUG:Sent:     {"emeter":{"get_realtime":{}}}
2019-09-23 15:50:04,329:__main__:DEBUG:Received: {"emeter":{"get_realtime":{"voltage_mv":235537,"current_ma":16,"power_mw":0,"total_wh":9,"err_code":0}}}
2019-09-23 15:50:04,329:__main__:DEBUG:json_data: {'emeter': {'get_realtime': {'current_ma': 16, 'err_code': 0, 'voltage_mv': 235537, 'power_mw': 0, 'total_wh': 9}}}
2019-09-23 15:50:04,330:__main__:DEBUG:IDX: 37, Item: voltage, Value: 235.54
2019-09-23 15:50:04,330:__main__:DEBUG:URL: http://192.168.2.1:8084/json.htm?type=command&param=udevice&nvalue=0&idx=37&svalue=235.54
2019-09-23 15:50:04,333:__main__:ERROR:HTTP error(None): None
2019-09-23 15:50:04,337:__main__:DEBUG:Command: {"system":{"get_sysinfo":{}}}
2019-09-23 15:50:04,337:__main__:DEBUG:Encoded string: b'{"system":{"get_sysinfo":{}}}'
2019-09-23 15:50:04,337:__main__:DEBUG:Encrypted Command: b'\x00\x00\x00\x1d\xd0\xf2\x81\xf8\x8b\xff\x9a\xf7\xd5\xef\x94\xb6\xd1\xb4\xc0\x9f\xec\x95\xe6\x8f\xe1\x87\xe8\xca\xf0\x8b\xf6\x8b\xf6'
2019-09-23 15:50:04,338:__main__:DEBUG:Encoded string: b'{"system":{"get_sysinfo":{}}}'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xd9\x98\xd9\xe1\xd7\x92\xa6\xe3\xd3\xe3\xd2\x94\xd0\xe7\xa4\xe5\xa3\x97\xa5\x9d\xab\x93\xd1\xe4\xa1\x83\xaf\x8d\xe3\x86\xfe\x8a\xd5\xb4\xd7\xa3\xca\xa5\xcb\xe9\xd3\xa8\x8a\xfe\x87\xf7\x92\xb0\x8a\xa7\x96\xeb\xc7\xe5\x80\xf2\x80\xdf\xbc\xd3\xb7\xd2\xf0\xca\xfa\x87\xfa\x87'
2019-09-23 15:50:04,438:__main__:DEBUG:Sent:     {"system":{"get_sysinfo":{}}}
2019-09-23 15:50:04,438:__main__:DEBUG:Received: {"system":{"get_sysinfo":{"sw_ver":"1.5.4 Build 180815 Rel.121440","hw_ver":"2.0","type":"IOT.SMARTPLUGSWITCH","model":"HS110(EU)","mac":"98:DA:C4:6A:7A:6F","dev_name":"Smart Wi-Fi Plug With Energy Monitoring","alias":"wasmachine-meter","relay_state":0,"on_time":0,"active_mode":"none","feature":"TIM:ENE","updating":0,"icon_hash":"","rssi":-56,"led_off":0,"longitude_i":0,"latitude_i":0,"hwId":"044A516EE63C875F9458DA25C2CCC5A0","fwId":"00000000000000000000000000000000","deviceId":"8006AE9F636BDBC209B19AAB642877631BAAB2A9","oemId":"1998A14DAA86E4E001FD7CAF42868B5E","next_action":{"type":-1},"err_code":0}}}
2019-09-23 15:50:04,439:__main__:DEBUG:json_data: {'system': {'get_sysinfo': {'type': 'IOT.SMARTPLUGSWITCH', 'rssi': -56, 'relay_state': 0, 'dev_name': 'Smart Wi-Fi Plug With Energy Monitoring', 'err_code': 0, 'hwId': '044A516EE63C875F9458DA25C2CCC5A0', 'model': 'HS110(EU)', 'on_time': 0, 'oemId': '1998A14DAA86E4E001FD7CAF42868B5E', 'hw_ver': '2.0', 'sw_ver': '1.5.4 Build 180815 Rel.121440', 'latitude_i': 0, 'alias': 'wasmachine-meter', 'led_off': 0, 'updating': 0, 'next_action': {'type': -1}, 'active_mode': 'none', 'longitude_i': 0, 'mac': '98:DA:C4:6A:7A:6F', 'feature': 'TIM:ENE', 'deviceId': '8006AE9F636BDBC209B19AAB642877631BAAB2A9', 'icon_hash': '', 'fwId': '00000000000000000000000000000000'}}}
2019-09-23 15:50:04,439:__main__:DEBUG:URL: http://192.168.2.1:8084/json.htm?type=command&param=udevice&idx=13&nvalue=0
2019-09-23 15:50:04,442:__main__:ERROR:HTTP error(None): None
When updating the script in domoticz is also gives the same output in the log:

2019-09-23 15:47:04.830 Error: EventSystem: Failed to execute python event script "Script #3"
2019-09-23 15:47:04.830 Error: EventSystem: Traceback (most recent call last):
2019-09-23 15:47:04.830 Error: EventSystem: File "<string>", line 51, in <module>
2019-09-23 15:47:04.830 Error: EventSystem: NameError: name '__file__' is not defined

I tested the url, and it updates the devices in domoticz nicely. So no changes... Can I try something else?

I'm running python 3.5.1 on synology, and I'm using a login.
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

@jaaap, I haven't got any more suggestions at the moment, but a few thoughts about your initial post.
1. Putty isn't 'stuck', it just won't return anything while the program is in a loop. Because we are 'handling' the error, the program doesn't crash out.
2. This is the wrong script to run from Domoticz Events. The plugin script is mentioned in my post https://www.domoticz.com/forum/viewtopi ... 60#p219532 where there is some explanation about it and a link to the author https://github.com/dahallgren/domoticz- ... /plugin.py It would be worth trying this plugin to see if it works in your situation with the Synology.

Cheers - Andrew
jaaap
Posts: 59
Joined: Sunday 28 July 2019 22:59
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by jaaap »

@ajay100 THANK YOU!!! :-) The feeling when everything works after 3 nights of figuring it out is just like a breath of fresh air after being in the sauna for hours :lol:

What did the trick was using the plugin you mentioned, and (very n00bish) placing it in the plugins folder of domoticz (before I thought plugins were just code I could paste in the domoticz events GUI. However, you cannot :-)

Thank you for all your patience and help. If someone is trying to figure the same thing out, hope this helps!
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

Thanks for getting back @jaaap, it's great to know you got it working.

Cheers - Andrew
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Geitje »

This plugin is running quite some time now without problems (as long as all devices are within reach, hope this error reporting can be solved sometime).

However I ran in somthing else: when opening the device log of any of my HS100 switches in Domoticz, Domoticz crashes. I know from my motion sensors the buildup can take some seconds if the log is very long. So I waited some minutes, but is does not show up, the CPU usage is not very high, so I think it is nog working then. I have to restart Domticz from the terminal. All other device logs work fine, it happens to all HS100 devices. Could it be the logs are very large? Or what could be the problem?
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

@Geitje, sorry I didn't get back sooner on the plugin errors. I'm not sure if this will help solve it, but you could try the following. Have a look at the error handling below - I have commented out the two 'raise' commands (which raises an error and exits the program) and above the first one added 'return ret'.

Code: Select all

    def _send_json_cmd(self, cmd):
        ret = {}
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.settimeout(1.5)
            sock.connect((Parameters["Address"], PORT))
            data = self._encrypt(cmd)
            sock.send(data)
            data = sock.recv(1024)
            Domoticz.Debug('data len: {}'.format(len(data)))
            sock.close()
        except socket.error as e:
            Domoticz.Log('send command error: {}'.format(str(e)))
            return ret
            #raise

        try:
            json_resp = self._decrypt(data[4:])
            ret = json.loads(json_resp)
        except (TypeError, JSONDecodeError) as e:
            Domoticz.Log('decode error: {}'.format(str(e)))
            Domoticz.Log('data: {}'.format(str(data)))
            #raise

        return ret
Then in the update_emeter_values function, I have simply added the line

Code: Select all

if result != {}:

Code: Select all

    def update_emeter_values(self):
        if Parameters["Mode1"] == "HS110":
            cmd = {
                "emeter": {
                    "get_realtime": {}
                }
            }

            result = self._send_json_cmd(json.dumps(cmd))
            Domoticz.Debug("got response: {}".format(result))
            
            if result != {}:
              realtime_result = result.get('emeter', {}).get('get_realtime', {})
              err_code = realtime_result.get('err_code', 1)

              if err_code == 0:
                  Devices[2].Update(nValue=0, sValue=str(realtime_result['current_ma'] / 1000))  #int(1 * realtime_result['current_ma']
                  Devices[3].Update(nValue=0, sValue=str(realtime_result['voltage_mv'] / 1000))  #int(1 * realtime_result['voltage_mv']
                  Devices[4].Update(nValue=0, sValue=str(realtime_result['power_mw'] / 1000))    #int(1 * realtime_result['power_mw']
(check all indenting is correct).

Now, when socket.error is true, '_send_json_cmd' returns the (empty) ret variable to the calling function 'update_emeter_values', which can now handle that empty value.

Testing this, when I switch off the HS110, I get the Domoticz log entry i.e. '2019-10-15 20:58:29.490 (HS110 Plugin) send command error: timed out'.

You will get a lot of errors in Domoticz if the HS1xx is off or out of range, but it should return values again once in range without having to restart Domoticz.

You could also try reducing sock.settimeout back to 1.5 to see if the error handling has resolved that problem. The Domoticz logs would then give you a clue as to when the HS1xx is not connecting.
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Geitje »

I tried these changes succesfully, will if it is stable.

I found out my Domoticz DB size is growing really fast, I i discovered the logs of the HS100 plugins are really large. Every 10 seconds an "on" command is written in the log. I checked, and even if the is no switch command whatsoever, this command is shown in the log. Can this be changed?
Attachments
Screenshot_20191206-153723.png
Screenshot_20191206-153723.png (131.5 KiB) Viewed 3132 times
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

@Geitje, mine is not logging each heartbeat like that. Check for

Code: Select all

Domoticz.Log()
lines in your code and try commenting out if you don't want logging to occur. Maybe in

Code: Select all

def get_switch_state(self):
section. If you can't see anything obvious then please post your code.
Cheers - Andrew
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Geitje »

Not sure, but I could not find the Domoticz.Log which is causing this...

Code: Select all

# Domoticz TP-Link Wi-Fi Smart Plug plugin
#
# Plugin based on reverse engineering of the TP-Link HS110, courtesy of Lubomir Stroetmann and Tobias Esser.
# https://www.softscheck.com/en/reverse-engineering-tp-link-hs110/
#
# Author: Dan Hallgren
#
"""
<plugin key="tplinksmartplug" name="TP-Link Wi-Fi Smart Plug HS100/HS110" version="0.1.0">
    <description>
        <h2>TP-Link Wi-Fi Smart Plug</h2>
        <ul style="list-sytel-type:square">
            <li>on/off switching</li>
            <li>emeter realtime power (HS110)</li>
            <li>emeter realtime current (HS110)</li>
            <li>emeter realtime voltage (HS110)</li>
        </ul>
        <h3>Devices</h3>
        <ul style="list-style-type:square">
            <li>switch - On/Off</li>
            <li>power - Realtime power in Watts</li>
            <li>current - Realtime current in ampere</li>
            <li>voltage - Voltage input</li>
        </ul>
    </description>
    <params>
        <param field="Address" label="IP Address" width="200px" required="true"/>
        <param field="Mode1" label="Model" width="150px" required="false">
             <options>
                <option label="HS100" value="HS100" default="true"/>
                <option label="HS110" value="HS110"  default="false"/>
                <option label="HS110v2" value="HS110v2"  default="false"/>
            </options>
        </param>
        <param field="Mode6" label="Debug" width="75px">
            <options>
                <option label="True" value="Debug"/>
                <option label="False" value="Normal"  default="true" />
            </options>
        </param>
    </params>
</plugin>
"""
import json
import socket

import Domoticz

PORT = 9999
STATES = ('off', 'on', 'unknown')


class TpLinkSmartPlugPlugin:
    enabled = False
    connection = None

    def __init__(self):
        self.interval = 6  # 6*10 seconds
        self.heartbeatcounter = 0

    def onStart(self):
        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)
            DumpConfigToLog()

        if len(Devices) == 0:
            Domoticz.Device(Name="switch", Unit=1, TypeName="Switch", Used=1).Create()
            Domoticz.Log("Tp-Link smart plug device created")

        if (Parameters["Mode1"] == "HS110" or Parameters["Mode1"] == "HS110v2") and len(Devices) <= 1:
            # Create more devices here
            Domoticz.Device(Name="(A)", Unit=2, Type=243, Subtype=23).Create()
            Domoticz.Device(Name="(V)", Unit=3, Type=243, Subtype=8).Create()
            Domoticz.Device(Name="(W)", Unit=4, Type=243, Subtype=29).Create()

        state = self.get_switch_state()
        if state in 'off':
            Devices[1].Update(0, '0')
        elif state in 'on':
            Devices[1].Update(1, '100')
        else:
            Devices[1].Update(1, '50')

    def onStop(self):
        # Domoticz.Log("onStop called")
        pass

    def onConnect(self, Connection, Status, Description):
        # Domoticz.Log("onConnect called")
        pass

    def onMessage(self, Connection, Data, Status, Extra):
        # Domoticz.Log("onMessage called")
        pass

    def onCommand(self, unit, command, level, hue):
        Domoticz.Log("onCommand called for Unit " +
                     str(unit) + ": Parameter '" + str(command) + "', Level: " + str(level))

        if command.lower() == 'on':
            cmd = {
                "system": {
                    "set_relay_state": {"state": 1}
                }
            }
            state = (1, '100')

        elif command.lower() == 'off':
            cmd = {
                "system": {
                    "set_relay_state": {"state": 0}
                }
            }
            state = (0, '0')

        result = self._send_json_cmd(json.dumps(cmd))
        Domoticz.Debug("got response: {}".format(result))

        err_code = result.get('system', {}).get('set_relay_state', {}).get('err_code', 1)

        if err_code == 0:
            Devices[1].Update(*state)

        # Reset counter so we trigger emeter poll next heartbeat
        self.heartbeatcounter = 0

    def onNotification(self, Name, Subject, Text, Status, Priority, Sound, ImageFile):
        Domoticz.Log("Notification: " + Name + "," + Subject + "," + Text + "," + Status +
                     "," + str(Priority) + "," + Sound + "," + ImageFile)

    def onDisconnect(self, Connection):
        # Domoticz.Log("onDisconnect called")
        pass

    def onHeartbeat(self):
        if self.heartbeatcounter % self.interval == 0:
            self.update_emeter_values()
        state = self.get_switch_state()
        if state in 'off':
            Devices[1].Update(0, '0')
        elif state in 'on':
            Devices[1].Update(1, '100')
        else:
            Devices[1].Update(1, '50')
        self.heartbeatcounter += 1

    def _encrypt(self, data):
        key = 171
        result = b"\x00\x00\x00" + chr(len(data)).encode('latin-1')
        for i in data.encode('latin-1'):
            a = key ^ i
            key = a
            result += bytes([a])
        return result

    def _decrypt(self, data):
        key = 171
        result = ""
        for i in data:
            a = key ^ i
            key = i
            result += bytes([a]).decode('latin-1')
        return result

    def _send_json_cmd(self, cmd):
        ret = {}
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.settimeout(1.5)
            sock.connect((Parameters["Address"], PORT))
            data = self._encrypt(cmd)
            sock.send(data)
            data = sock.recv(1024)
            Domoticz.Debug('data len: {}'.format(len(data)))
            sock.close()
        except socket.error as e:
            Domoticz.Log('send command error: {}'.format(str(e)))
            return ret
            #raise

        try:
            json_resp = self._decrypt(data[4:])
            ret = json.loads(json_resp)
        except (TypeError, JSONDecodeError) as e:
            Domoticz.Log('decode error: {}'.format(str(e)))
            Domoticz.Log('data: {}'.format(str(data)))
            #raise

        return ret
    def update_emeter_values(self):
        if Parameters["Mode1"] == "HS110":
            cmd = {
                "emeter": {
                    "get_realtime": {}
                }
            }

            result = self._send_json_cmd(json.dumps(cmd))
            Domoticz.Debug("got response: {}".format(result))

            realtime_result = result.get('emeter', {}).get('get_realtime', {})
            err_code = realtime_result.get('err_code', 1)

            if err_code == 0:
                Devices[2].Update(nValue=0, sValue=str(round(realtime_result['current'],2)))
                Devices[3].Update(nValue=0, sValue=str(round(realtime_result['voltage'],2)))
                Devices[4].Update(nValue=0, sValue=str(round(realtime_result['power'],2)) + ";" + str(realtime_result['total']*1000))
        if Parameters["Mode1"] == "HS110v2":
            cmd = {
                "emeter": {
                    "get_realtime": {}
                }
            }

            result = self._send_json_cmd(json.dumps(cmd))
            Domoticz.Debug("got response: {}".format(result))

            if result != {}:
              realtime_result = result.get('emeter', {}).get('get_realtime', {})
              err_code = realtime_result.get('err_code', 1)

              if err_code == 0:
                  Devices[2].Update(nValue=0, sValue=str(round(realtime_result['current_ma']/1000,2)))
                  Devices[3].Update(nValue=0, sValue=str(round(realtime_result['voltage_mv']/1000,2)))
                  Devices[4].Update(nValue=0, sValue=str(round(realtime_result['power_mw']/1000,2)) + ";" + str(realtime_result['total_wh']))

#power = round(float(json_data['emeter']['get_realtime']['power_mw']) / 1000,2)


    def get_switch_state(self):
        cmd = {
            "system": {
                "get_sysinfo": "null"
            }
        }
        result = self._send_json_cmd(json.dumps(cmd))
        print(result)

        err_code = result.get('system', {}).get('get_sysinfo', {}).get('err_code', 1)

        if err_code == 0:
            state = result['system']['get_sysinfo']['relay_state']
        else:
            state = 2

        return STATES[state]


global _plugin
_plugin = TpLinkSmartPlugPlugin()


def onStart():
    global _plugin
    _plugin.onStart()


def onStop():
    global _plugin
    _plugin.onStop()


def onConnect(Connection, Status, Description):
    global _plugin
    _plugin.onConnect(Connection, Status, Description)


def onMessage(Connection, Data, Status, Extra):
    global _plugin
    _plugin.onMessage(Connection, Data, Status, Extra)


def onCommand(Unit, Command, Level, Hue):
    global _plugin
    _plugin.onCommand(Unit, Command, Level, Hue)


def onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile):
    global _plugin
    _plugin.onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile)


def onDisconnect(Connection):
    global _plugin
    _plugin.onDisconnect(Connection)


def onHeartbeat():
    global _plugin
    _plugin.onHeartbeat()


# Generic helper functions
def DumpConfigToLog():
    for x in Parameters:
        if Parameters[x] != "":
            Domoticz.Debug("'" + x + "':'" + str(Parameters[x]) + "'")
    Domoticz.Debug("Device count: " + str(len(Devices)))
    for x in Devices:
        Domoticz.Debug("Device:           " + str(x) + " - " + str(Devices[x]))
        Domoticz.Debug("Device ID:       '" + str(Devices[x].ID) + "'")
        Domoticz.Debug("Device Name:     '" + Devices[x].Name + "'")
        Domoticz.Debug("Device nValue:    " + str(Devices[x].nValue))
        Domoticz.Debug("Device sValue:   '" + Devices[x].sValue + "'")
        Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
    return

Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

@geitje, my apologies, I was looking at the Domoticz log not the device log. So mine is doing the same thing and my last post should be ignored. I am looking at a test now to check the state before updating Domoticz.
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Geitje »

No problem, hope you can find it.
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

I have modified the original Domoticz TP-Link plugin script from Dan Hallgren to incorporate various requests. You can find it at https://github.com/ajay10000/domoticz_hs110_plugin

@CV8R you can suppress error messages if the TP-Link is switched off.

@Geitje, you can prevent duplicate device logs if the switch state doesn't change.

Various TP-Link models are hopefully catered for i.e. HS100/110/v2, however I only have an HS110 to test with (not v2). My HS110 reports in milli-V/A/W.

Any suggestions or comments welcome.

Cheers - Andrew
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Geitje »

Thanks Andrew,

So far it is working great. The many device log-registrations are over, switching works, and it also reports back to Domoticz when switching using the Kasa app.
I do not own a HS110, so energy use reporting I cannot check.

Thanks for your work!
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
Darkneo
Posts: 24
Joined: Sunday 10 February 2019 16:22
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Darkneo »

Hi there and thanks for this script (that I still had many problem to start, due to DOS2Unix problems... :'( )

Now the script is executing on both domoticz and SSH.... But nothing happens on the switch....

On SSH, I have the command:

Code: Select all

Sent:      {"system":{"set_relay_state":{"state":0}}}
Received:
Nothing in Domoticz Logs... Seems like the switch is not answering.... I am trying on an HS110
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

@Darkneo, sending the switch command directly from the shell as you have done is a good way to troubleshoot. Example - turn the relay off:

Code: Select all

python tplink_hs110.py -c off
Have you tried setting debugging on to see if that provides any clues?

Code: Select all

debug_level="DEBUG"
Darkneo
Posts: 24
Joined: Sunday 10 February 2019 16:22
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Darkneo »

Hi, and thanks for your reply (and happy new year! :mrgreen: )

The script I am using is the "tplink-smartplug.py" (I guess the first version). I'll give a try using your latest post on git and keep you informed!
Kubinks
Posts: 1
Joined: Monday 06 January 2020 12:23
Target OS: Linux
Domoticz version: 4.9701
Location: Poland
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Kubinks »

@ajay100, first of all thanks for your work.

From your github link, line 222 you are missing
+ ";" + str(realtime_result['total_wh'])
It needs to look like this
Devices[4].Update(nValue=0, sValue=str(round(realtime_result['power_mw']/1000,2)) + ";" + str(realtime_result['total_wh']))
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

Re: TP-Link smart plug HS100/HS110

Post by ajay100 »

@Kubinks, thanks for your feedback. I had deleted that bit of code because it didn't seem to be doing anything. Your post encouraged me to find out what was going on.

Code: Select all

Devices[4].Update(nValue=0, sValue=str(round(realtime_result['power_mw']/1000,2)) + ";" + str(realtime_result['total_wh']))
This code you (and also lordzurp) posted updates a specific device type/subtype with both instantaneous power in Watts and energy used in kWh. Adding this in to my code didn't produce the expected results, for several reasons.

1. I had the wrong subtype initially for HS110 Power, in the code where the device is created. This is the correct type/subtype:

Code: Select all

Domoticz.Device(Name="emeter power (W)", Unit=4, Type=243, Subtype=29).Create()  # Subtype 29 is kWh
For reference, the device types can be found here: https://github.com/domoticz/domoticz/bl ... aretypes.h
General device Type 243 = pTypeGeneral = 0xF3 hex. kWh Subtype 29 = sTypeKwh = 0x1D hex.

2. I didn't delete the plugin device in the Devices page, when changing its subtype, as I had expected it to update itself. If you wish to change any device parameters you must delete the device. However you don't need to delete all of the Devices created by the plugin Hardware to change only one.

3. The code didn't allow devices to be created and/or changed after the first run, unless all of the devices were deleted. This was due to the condition

Code: Select all

len(Devices) <= 1
in the line

Code: Select all

if (Parameters["Mode1"] == "HS110" or Parameters["Mode1"] == "HS110v2") and len(Devices) <= 1:
I didn't want to delete all of the history for the Switch, Volts and Amps devices, so I have worked around this by creating a boolean user variable 'create_device' and modifying the above line to:

Code: Select all

if "HS110" in Parameters["Mode1"] and create_device:
I have added some more explanation in the Readme and updated the code on my GitHub https://github.com/ajay10000/domoticz_hs110_plugin.

This took me quite a while to work out and some of it may seem like common sense when you have a deeper understanding of how Domoticz works. If anyone has any thoughts or corrections, they are welcome.

Cheers - Andrew
boshiant
Posts: 1
Joined: Monday 13 January 2020 1:28
Target OS: -
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by boshiant »

MikeF wrote: Thursday 06 October 2016 23:32 I'm really at a loss to explain this. I just downloaded the python script again (on my Apple Mac), saved it with a different filename (HS110.py), and copied it across to my Raspberry Pi that runs Domoticz. I changed the 'on' and 'off' commands to pick up the new filename, clicked on the dummy switch icon in Domoticz, and turned it off and back on again (monitoring it via the Kasa app).

The permissions I have on the Pi are:

Code: Select all

-rwxr-xr-x 1 pi pi 3062 Oct  6 22:21 HS110.py
The Domoticz command I have is:

Code: Select all

script:///home/pi/devices/HS110.py -t 192.168.0.84 -c on
thank you i fixed
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest