Great!

Moderator: leecollings
Thanks for your continued work on this plugin. I do have a question though: your readme states that you will need te PP manager installed for this plugin to work. However; I am running Domoticz on a Windows machine where this is not usable. Is there any way to use your plugin still? One of the older versions seems to work, though it will only make a switch device and does not allow me to read the current usage (or I am doing something horribly wrong) Scrap that; it is no longer working at all...ajay100 wrote: ↑Saturday 11 January 2020 4:10 @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.
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.Code: Select all
Devices[4].Update(nValue=0, sValue=str(round(realtime_result['power_mw']/1000,2)) + ";" + str(realtime_result['total_wh']))
1. I had the wrong subtype initially for HS110 Power, in the code where the device is created. This is the correct type/subtype:
For reference, the device types can be found here: https://github.com/domoticz/domoticz/bl ... aretypes.hCode: Select all
Domoticz.Device(Name="emeter power (W)", Unit=4, Type=243, Subtype=29).Create() # Subtype 29 is kWh
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 conditionin the lineCode: Select all
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 (Parameters["Mode1"] == "HS110" or Parameters["Mode1"] == "HS110v2") and len(Devices) <= 1:
I have added some more explanation in the Readme and updated the code on my GitHub https://github.com/ajay10000/domoticz_hs110_plugin.Code: Select all
if "HS110" in Parameters["Mode1"] and create_device:
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
Code: Select all
# Begin user editable variables
version = 3.5
logger_name = "hs110-2" #used for log file names, messages, etc
debug_level="INFO" # debug options DEBUG, INFO, WARNING, ERROR, CRITICAL
delay_time = 5 #update time in seconds
domain="http://127.0.0.1:8090/"
base_url = domain + "json.htm?type=command¶m=udevice&nvalue=0"
monitor_list = ["voltage","current","power","usage"]
domoticz_idx = [90,91,108,93]
hs110_ip = "192.168.0.99"
text_logging = True
track_state = True
hs110_switch_idx = 84
encoding = "utf-8" # latin-1
datafile_columns = "Time,Voltage,Current,Power (W),Usage (kWh)"
dailyfile_columns = "Date-Time,Usage (kWh)"
# End user editable variables
Code: Select all
python3 tplink_hs110.py -c energy
Code: Select all
2020-04-23 14:40:02.074 Error: (python-plugin-manager) 'onHeartbeat' failed 'KeyError'.
2020-04-23 14:40:02.074 Error: (python-plugin-manager) ----> Line 285 in '/home/pi/domoticz/plugins/hs110/plugin.py', function onHeartbeat
2020-04-23 14:40:02.074 Error: (python-plugin-manager) ----> Line 138 in '/home/pi/domoticz/plugins/hs110/plugin.py', function onHeartbeat
2020-04-23 14:40:02.074 Error: (python-plugin-manager) ----> Line 221 in '/home/pi/domoticz/plugins/hs110/plugin.py', function update_emeter_values
Hi @mikje, a suggestion would be to try a Domoticz User variable in your Lua script. See https://www.domoticz.com/wiki/User_variables. Set your variable up in the web interface first, then update it in your script and use that to get the time difference.mikje wrote: ↑Tuesday 21 April 2020 22:03 I have installed the script in systemctl and it is working (every 15 sec)
In lua (within domoticz) i read the otherdevices_lastupdate to see when my hs110 went on.
If it is on for 5 minutes and doesnt provide any power i want to turn it off to forecome overload of my battery charger connected to it.
But... the lastupdate time is updated every 15 seconds (i think it is the systemctl script.
How to prevent this? (setting the 15 seconds higher is not an option since i have to read the values in my lua script.
The lua script is:
t1 = os.time()
s = otherdevices_lastupdate['fietststekker aan uit']
-- returns a date time like 2013-07-11 17:23:12
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
commandArray = {}
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds} ;
difference = (os.difftime (t1, t2));
if ( (otherdevices['fietststekker aan uit'] == 'On') and (difference > 300) and (difference < 1700) and (tonumber((otherdevices['Fiets Ampere'])) < 0.1)) then
commandArray['fietststekker aan uit']='Off';
end
return commandArray
I gave this plugin a try, but it won't show under hardware. I changed domain to 127.0.0.1 instead of RPI4, but that didn't help either.ajay100 wrote: ↑Sunday 26 April 2020 6:33 Hi @Alain, Python Plugin Manager is not supported in Windows and the HS100/110 Domoticz plugin was designed to be used with that. I suggested to another member that they try the standalone version https://github.com/ajay10000/TP-Link-HS110 in Windows.
Hi Andrew,ajay100 wrote: ↑Thursday 07 May 2020 9:33 Hi @nosehook, to give you any feedback we would need to know where you got the HS110 plugin from, as there are several different versions. You can also copy and post the Domoticz log related to the HS110 plugin. Also check and post your settings from the top of the plugin script if possible.
Cheers - Andrew
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/
#
# Original Author: Dan Hallgren
# Modified by: Andrew P
#
"""
<plugin key="tplinksmartplug" name="TP-Link Wi-Fi Smart Plug HS100/HS110/v2" version="0.2.5">
<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/v2)</li>
<li>emeter realtime current (HS110/v2)</li>
<li>emeter realtime voltage (HS110/v2)</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 amps</li>
<li>voltage - Realtime voltage in volts</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, socket, Domoticz
# Start user editable variables
base_url = "http://192.168.0.115:8080/" # Modify with your IP# or domain
interval = 1 # heartbeat in 10 second multiples
HS110_divider = 1000 # 1000 or 1 depending on your hardware version of HS110
suppress_socket_error = False # Suppress error messages in Domoticz after the first
create_device = True # True if you need to create a device.
# End user editable variables
Code: Select all
2020-05-07 10:19:06.136 (TP-Link HS-110V2 Verdeelblok) Pushing 'onHeartbeatCallback' on to queue
2020-05-07 10:19:06.157 (TP-Link HS-110V2 Verdeelblok) Processing 'onHeartbeatCallback' message
2020-05-07 10:19:06.158 (TP-Link HS-110V2 Verdeelblok) Calling message handler 'onHeartbeat'.
2020-05-07 10:19:06.227 (TP-Link HS-110V2 Verdeelblok) data len: 625
2020-05-07 10:19:06.271 (TP-Link HS-110V2 Verdeelblok) Result: {'system': {'get_sysinfo': {'sw_ver': '1.5.4 Build 180815 Rel.121440', 'hw_ver': '2.0', 'type': 'IOT.SMARTPLUGSWITCH', 'model': 'HS110(EU)', 'mac': 'xxx', 'dev_name': 'Smart Wi-Fi Plug With Energy Monitoring', 'alias': 'Verdeelblok', 'relay_state': 1, 'on_time': 2357, 'active_mode': 'schedule', 'feature': 'TIM:ENE', 'updating': 0, 'icon_hash': '', 'rssi': -59, 'led_off': 0, 'longitude_i': lon, 'latitude_i': lat, 'hwId': 'xxx', 'fwId': '00000000000000000000000000000000', 'deviceId': 'xxxx', 'oemId': 'xxx', 'next_action': {'type': -1}, 'err_code': 0}}}
2020-05-07 10:19:06.272 (TP-Link HS-110V2 Verdeelblok) Last state: on, Switch state: on, Domoticz device state: on
Hi Ajay100,ajay100 wrote: ↑Thursday 07 May 2020 11:43 @nosehook, you have debugging turned on, which is great. In your Domoticz log you should be seeing an emeter result as well as the get_sysinfo result. It will look similar to this:
2020-05-07 19:21:03.266 (HS110 Plugin) got response: {'emeter': {'get_realtime': {'voltage_mv': 242130, 'current_ma': 14, 'power_mw': 0, 'total_wh': 1, 'err_code': 0}}}
There are two elements that determine if self.update_emeter_values() is called:
1. line 137 if self.heartbeatcounter % self.interval == 0:
This should be working hopefully. Your heartbeat interval is 1 x 10 = 10 seconds
2. line 205 if Parameters["Mode1"] in "HS110":
This parameter is set in Domoticz Hardware, Model: HS110 (just below IP Address: and above Debug:)
Let us know what you find.
Users browsing this forum: No registered users and 1 guest