Re: TP-Link smart plug HS100/HS110
Posted: Thursday 30 May 2019 18:08
It is working now. Thank you so much for getting this to work!
Open source Home Automation System
https://forum.domoticz.com/
Code: Select all
def onHeartbeat(self):
if self.heartbeatcounter % self.interval == 0:
self.update_emeter_values()
# Get the switch state as well.
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
Code: Select all
self.update_emeter_values()
Code: Select all
self.interval = 6 # 6*10 seconds
Code: Select all
<option label="HS100" value="HS100" default="true"/>
<option label="HS110" value="HS110" default="false"/>
<option label="HS110v2" value="HS110v2" default="false"/>
Code: Select all
Domoticz.Device(Name="(W)", Unit=4, Type=243, Subtype=29).Create()
Code: Select all
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))
Code: Select all
if Parameters["Mode1"] == "HS110v2":
[...]
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']))
Thanks, working as expected. Finally I could forget my previous cron based bash script to catch datalordzurp wrote: ↑Monday 22 July 2019 11:37 Hello guys !
this is my first post on this board (but not first on a board ...)
I just made a fresh install of my rPI with domoticz, and finally set up a clean way to manage HS110 plug
I started with this plugin : https://github.com/dahallgren/domoticz-tplink-smartplug, tweaked a little with some helpfully pieces of code from previous replies, and a pinch of homemade code
I had to manage with the 2 versions of HS110, v1 which speak in full units, and the v2 which work with millis
here is the result : https://github.com/lordzurp/domoticz-tplink-smartplug
New device typechange Domoticz device type, to properly report power consumptionCode: Select all
<option label="HS100" value="HS100" default="true"/> <option label="HS110" value="HS110" default="false"/> <option label="HS110v2" value="HS110v2" default="false"/>
rounded results, to avoid 2.377066 useless headhache, and adding the total power consumption reported by the plugCode: Select all
Domoticz.Device(Name="(W)", Unit=4, Type=243, Subtype=29).Create()
a new branch for v2, with /1000 scalingCode: Select all
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))
and minor corrections to work with the new v2 typeCode: Select all
if Parameters["Mode1"] == "HS110v2": [...] 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']))
hopefully it will work on your system![]()
you're welcome
same here. I lost my crontab when I reflashed the µSD, so got in search of a proper solution, and voila
Code: Select all
2019-07-28 22:24:57.749 Error: (TPlink HS 100 IP.8) 'onCommand' failed 'timeout'.
2019-07-28 22:24:57.750 Error: (TPlink HS 100 IP.8) ----> Line 275 in '/home/pi/domoticz/plugins/domoticz-tplink-smartplug/plugin.py', function onCommand
2019-07-28 22:24:57.750 Error: (TPlink HS 100 IP.8) ----> Line 116 in '/home/pi/domoticz/plugins/domoticz-tplink-smartplug/plugin.py', function onCommand
2019-07-28 22:24:57.750 Error: (TPlink HS 100 IP.8) ----> Line 178 in '/home/pi/domoticz/plugins/domoticz-tplink-smartplug/plugin.py', function _send_json_cmd
2019-07-28 22:25:00.272 Error: (TPlink HS 100 IP.8) 'onHeartbeat' failed 'timeout'.
2019-07-28 22:25:00.272 Error: (TPlink HS 100 IP.8) ----> Line 290 in '/home/pi/domoticz/plugins/domoticz-tplink-smartplug/plugin.py', function onHeartbeat
2019-07-28 22:25:00.272 Error: (TPlink HS 100 IP.8) ----> Line 138 in '/home/pi/domoticz/plugins/domoticz-tplink-smartplug/plugin.py', function onHeartbeat
2019-07-28 22:25:00.272 Error: (TPlink HS 100 IP.8) ----> Line 236 in '/home/pi/domoticz/plugins/domoticz-tplink-smartplug/plugin.py', function get_switch_state
2019-07-28 22:25:00.272 Error: (TPlink HS 100 IP.8) ----> Line 178 in '/home/pi/domoticz/plugins/domoticz-tplink-smartplug/plugin.py', function _send_json_cmd
Code: Select all
sock.settimeout(1.5)
Cheers Andrew. Apologies, I wasn't subscribed to the thread. Sorted now.Thanks for the info @CV8R. I agree the errors are annoying when the device is switched off. I'll see if something can be done about that in a few weeks when I have my hands on the HS110 again.
Code: Select all
2019-09-23 13:19:59,447:__main__:INFO:hs110-3 version 3.5 has started...
2019-09-23 13:19:59,455:__main__:DEBUG:Command: {"emeter":{"get_realtime":{}}}
2019-09-23 13:19:59,456:__main__:DEBUG:Encoded string: b'{"emeter":{"get_realtime":{}}}'
2019-09-23 13:19:59,456:__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 13:19:59,457:__main__:DEBUG:Encoded string: b'{"emeter":{"get_realtime":{}}}'
2019-09-23 13:19:59,502:__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\xe2\xd2\xe6\xd4\xed\xc1\xe3\x80\xf5\x87\xf5\x90\xfe\x8a\xd5\xb8\xd9\xfb\xc1\xf0\xc6\xea\xc8\xb8\xd7\xa0\xc5\xb7\xe8\x85\xf2\xd0\xea\xda\xf6\xd4\xa0\xcf\xbb\xda\xb6\xe9\x9e\xf6\xd4\xee\xd7\xfb\xd9\xbc\xce\xbc\xe3\x80\xef\x8b\xee\xcc\xf6\xc6\xbb\xc6\xbb'
2019-09-23 13:19:59,503:__main__:DEBUG:Sent: {"emeter":{"get_realtime":{}}}
2019-09-23 13:19:59,503:__main__:DEBUG:Received: {"emeter":{"get_realtime":{"voltage_mv":240429,"current_ma":16,"power_mw":0,"total_wh":9,"err_code":0}}}
2019-09-23 13:19:59,504:__main__:DEBUG:json_data: {'emeter': {'get_realtime': {'total_wh': 9, 'power_mw': 0, 'current_ma': 16, 'err_code': 0, 'voltage_mv': 240429}}}
2019-09-23 13:19:59,504:__main__:DEBUG:IDX: 37, Item: voltage, Value: 240.43
2019-09-23 13:19:59,505:__main__:DEBUG:URL: http://192.168.2.1:8084/json.htm?type=command¶m=udevice&nvalue=0&idx=37&svalue=240.43
2019-09-23 13:19:59,527:__main__:ERROR:HTTP error(None): None
2019-09-23 13:19:59,530:__main__:DEBUG:Command: {"system":{"get_sysinfo":{}}}
2019-09-23 13:19:59,531:__main__:DEBUG:Encoded string: b'{"system":{"get_sysinfo":{}}}'
2019-09-23 13:19:59,531:__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 13:19:59,531:__main__:DEBUG:Encoded string: b'{"system":{"get_sysinfo":{}}}'
2019-09-23 13:19:59,612:__main__:DEBUG:data: b'\x00\x00\x02d\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\x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d8\xbc\xd9\xfb\xc1\xf1\x8c\xf1\x8c'
2019-09-23 13:19:59,613:__main__:DEBUG:Sent: {"system":{"get_sysinfo":{}}}
2019-09-23 13:19:59,613:__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":1,"on_time":848,"active_mode":"none","feature":"TIM:ENE","updating":0,"icon_hash":"","rssi":-58,"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 13:19:59,614:__main__:DEBUG:json_data: {'system': {'get_sysinfo': {'feature': 'TIM:ENE', 'led_off': 0, 'fwId': '00000000000000000000000000000000', 'type': 'IOT.SMARTPLUGSWITCH', 'rssi': -58, 'hw_ver': '2.0', 'next_action': {'type': -1}, 'on_time': 848, 'sw_ver': '1.5.4 Build 180815 Rel.121440', 'model': 'HS110(EU)', 'oemId': '1998A14DAA86E4E001FD7CAF42868B5E', 'icon_hash': '', 'active_mode': 'none', 'alias': 'wasmachine-meter', 'hwId': '044A516EE63C875F9458DA25C2CCC5A0', 'mac': '98:DA:C4:6A:7A:6F', 'deviceId': '8006AE9F636BDBC209B19AAB642877631BAAB2A9', 'relay_state': 1, 'dev_name': 'Smart Wi-Fi Plug With Energy Monitoring', 'err_code': 0, 'latitude_i': 0, 'updating': 0, 'longitude_i': 0}}}
2019-09-23 13:19:59,614:__main__:DEBUG:URL: http://192.168.2.1:8084/json.htm?type=command¶m=udevice&idx=13&nvalue=1
2019-09-23 13:19:59,617:__main__:ERROR:HTTP error(None): None