TP-Link smart plug HS100/HS110

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

Moderator: leecollings

MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: TP-Link smart plug HS100/HS110

Post by MikeF »

boshiant wrote: Monday 13 January 2020 1:31 thank you i fixed
Great! :D
Notna
Posts: 1
Joined: Thursday 23 January 2020 10:58
Target OS: Windows
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Notna »

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.

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
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...

Just wanted to check what version you recommend to use on a Windows machine, using the HS110 V2. For your reference:

1. Downloaded this file: https://github.com/ajay10000/TP-Link-HS ... k_hs110.py and installed latest stable version of Python for all users.
2. Adjusted the top part of the .py like so:

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&param=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
3. Place that in the (x86) /plugin/ folder of Domoticz
3. Restarted Domoticz
4. Go to Hardware tab to add a new hardware entry but it does not display the plugin at all? Not a warning in the log either; just nada..
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 @Notna, I am using a Raspberry Pi platform for Domoticz, so I haven't tested this on Windows. However I believe the HS110 python script should work for you, from any of the previously mentioned sources, or mine at https://github.com/ajay10000/TP-Link-HS110. This is run from the python shell rather than being a Domoticz plugin.
  • The python shell script is perhaps a little more flexible for different applications and may work on more platforms.
  • The python Domoticz plugin may be easier for some users to set up and is more closely integrated with Domoticz.
Both scripts will switch a mains voltage device on and off when connected to the TP-Link HS100 or HS110, and will keep Domoticz updated with the switch setting.

They will both update Domoticz with Voltage, Current and Power readings from a HS110 type device.

In Windows, there will be a different way to run the script at startup, but try running commands from the python shell at first to test.

Choose your version (python 2 or 3) according to what you have installed. I have decided to only support v3 going forward.

Cheers - Andrew
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 »

To clarify, the python standalone script is saved somewhere convenient to run from the python shell. Set up the parameters in the 'User Editable Variables' section, CD to the folder, then run for example:

Code: Select all

python3 tplink_hs110.py -c energy
This script is not installed in the Domoticz plugin folder.
mikje
Posts: 3
Joined: Thursday 13 February 2020 9:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by mikje »

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
Helly
Posts: 1
Joined: Thursday 23 April 2020 14:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Helly »

@ajay100: I've installed your plugin and added my HS110 in Domoticz and switching on and off works fine, but where can I find the energy measurements? I don't see those anywhere.

Edit: I see the energy measurement in Domoticz now, but they all show 0.
In the Kasa app measurements are shown correctly.

My plug says 'Ver:3.1' on the back, app says 'Hardware Version 2.0'
The log shows:

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
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 »

@Helly, try changing the HS110_divider variable to 1. The value of this variable tells the script, around line 220, to manage for the two different versions of HS110 commands (as discussed elsewhere in this thread). i.e. current_ma, voltage_mv, power_mw OR current, voltage, power.
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 »

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
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.

Cheers - Andrew
Alain
Posts: 166
Joined: Sunday 26 April 2020 5:27
Target OS: Linux
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Alain »

I have tried Ajay100's version of the plugin in Domoticz (running on Windows PC)but it won't show up under hardware.

I also tried lordzurp's version and as soon as I configure one of my HS-110 switches, Domoticz automatically shuts down. I have been trying to find out why, but can't find it. It's not showing anything strange in de log when I start it.

I am pretty new to this. Just installed Domoticz a few days ago and have been trying to add all the different products I have at home. We have a lot of automation in our home, but everything is stand-alone, so I'm trying to combine everything.
Hue | Zigbee2Mqtt | MQTT | P1 | Xiaomi | RFXCom | Modbus | Qlima | Solaredge
TP-Link | Plugwise | Thermosmart | Node-Red | Grafana | Master and 5 remote servers
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 @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.
Alain
Posts: 166
Joined: Sunday 26 April 2020 5:27
Target OS: Linux
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Alain »

Hi Ajay100,

Ok, I will give that a try this coming weekend.
I'm having alot of fun exploring new possibilities with Domoticz. I want to try and connect our 4 Qlima airco's, as they also have a WiFi module, and once I start getting this going nicely, I also want to expand with an Opentherm gateway to connect our Vaillant boiler and Techneco Elga heat pump.

Too bad you can't connect an Abus Secvest security alarm, because we also have our smoke detectors connected to that.
Hue | Zigbee2Mqtt | MQTT | P1 | Xiaomi | RFXCom | Modbus | Qlima | Solaredge
TP-Link | Plugwise | Thermosmart | Node-Red | Grafana | Master and 5 remote servers
Alain
Posts: 166
Joined: Sunday 26 April 2020 5:27
Target OS: Linux
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Alain »

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.
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.
Hue | Zigbee2Mqtt | MQTT | P1 | Xiaomi | RFXCom | Modbus | Qlima | Solaredge
TP-Link | Plugwise | Thermosmart | Node-Red | Grafana | Master and 5 remote servers
Alain
Posts: 166
Joined: Sunday 26 April 2020 5:27
Target OS: Linux
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Alain »

I tried the lordzurp plugin again, but it causes Domoticz to automatically shutdown. I'm not getting any error messages. As long as I don't configure a hardware device from the TP-link plugin, Domoticz is stable. As soon as I configure a switch, this happens. The last time, I set debugging to "true" and this is what I get. All of a sudden everything stops:

2020-05-01 11:40:05.843 Status: TCPServer: shared server started...
2020-05-01 11:40:05.844 Status: RxQueue: queue worker started...
2020-05-01 11:40:07.847 Status: Thermosmart: Worker started...
2020-05-01 11:40:07.847 Status: (Smartswitch airco werkkamer) Started.
2020-05-01 11:40:07.847 Status: BuienRadar: Worker started...
2020-05-01 11:40:07.847 Status: Philips Hue: Worker started...
2020-05-01 11:40:07.848 Status: SolarEdgeAPI Worker started...
2020-05-01 11:40:07.848 Status: Thermosmart: Worker started...
2020-05-01 11:40:07.848 Status: SolarEdgeAPI Worker started...
2020-05-01 11:40:07.848 Status: NotificationSystem: thread started...
2020-05-01 11:40:07.848 Status: EventSystem: reset all events...
2020-05-01 11:40:07.856 Status: EventSystem: reset all device statuses...
2020-05-01 11:40:08.465 (Smartswitch airco werkkamer) Debug logging mask set to: PYTHON PLUGIN QUEUE IMAGE DEVICE CONNECTION MESSAGE ALL
2020-05-01 11:40:08.465 (Smartswitch airco werkkamer) 'HardwareID':'13'
2020-05-01 11:40:08.465 (Smartswitch airco werkkamer) 'HomeFolder':'D:\Program Files (x86)\Domoticz\plugins\domoticz-tplink-smartplug\'
2020-05-01 11:40:08.465 (Smartswitch airco werkkamer) 'StartupFolder':'D:\Program Files (x86)\Domoticz\'
2020-05-01 11:40:08.465 (Smartswitch airco werkkamer) 'UserDataFolder':'D:\Program Files (x86)\Domoticz\'
2020-05-01 11:40:08.465 (Smartswitch airco werkkamer) 'Database':'C:\ProgramData\Domoticz\domoticz.db'
2020-05-01 11:40:08.465 (Smartswitch airco werkkamer) 'Language':'en'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'Version':'0.1.0'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'Name':'Smartswitch airco werkkamer'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'Address':'192.168.0.85'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'Port':'0'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'Key':'tplinksmartplug'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'Mode1':'HS110'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'Mode6':'Debug'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'DomoticzVersion':'2020.1'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'DomoticzHash':'63fa969e4'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) 'DomoticzBuildTime':'2020-03-22 15:16:16'
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) Device count: 4
2020-05-01 11:40:08.466 (Smartswitch airco werkkamer) Device: 1 - ID: 54, Name: 'Smartswitch airco werkkamer - switch', nValue: 1, sValue: '100'
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device ID: '54'
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device Name: 'Smartswitch airco werkkamer - switch'
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device nValue: 1
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device sValue: '100'
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device LastLevel: 100
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device: 2 - ID: 55, Name: 'Smartswitch airco werkkamer - (A)', nValue: 0, sValue: ''
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device ID: '55'
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device Name: 'Smartswitch airco werkkamer - (A)'
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device nValue: 0
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device sValue: ''
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device LastLevel: 0
2020-05-01 11:40:08.467 (Smartswitch airco werkkamer) Device: 3 - ID: 56, Name: 'Smartswitch airco werkkamer - (V)', nValue: 0, sValue: ''
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device ID: '56'
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device Name: 'Smartswitch airco werkkamer - (V)'
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device nValue: 0
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device sValue: ''
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device LastLevel: 0
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device: 4 - ID: 57, Name: 'Smartswitch airco werkkamer - (W)', nValue: 0, sValue: ''
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device ID: '57'
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device Name: 'Smartswitch airco werkkamer - (W)'
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device nValue: 0
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device sValue: ''
2020-05-01 11:40:08.468 (Smartswitch airco werkkamer) Device LastLevel: 0
2020-05-01 11:40:08.627 (Smartswitch airco werkkamer) data len: 627
2020-05-01 11:40:08.628 (Smartswitch airco werkkamer - switch) Updating device from 1:'100' to have values 1:'100'.
2020-05-01 11:40:08.997 (Philips Hue) Color Switch (Brievenbus)
2020-05-01 11:40:08.085 Status: Python EventSystem: Initalizing event module.
2020-05-01 11:40:08.088 Status: EventSystem: Started
2020-05-01 11:40:08.088 Status: EventSystem: Queue thread started...
2020-05-01 11:40:08.308 Status: PluginSystem: Entering work loop.
2020-05-01 11:40:08.462 Status: (Smartswitch airco werkkamer) Entering work loop.
2020-05-01 11:40:08.462 Status: (Smartswitch airco werkkamer) Initialized version 0.1.0
2020-05-01 11:40:09.015 (Philips Hue) Light/Switch (Ezra)
2020-05-01 11:40:09.036 (Philips Hue) Light/Switch (Bijkeuken)
2020-05-01 11:40:09.058 (Philips Hue) Color Switch (Singer hoek)
2020-05-01 11:40:09.078 (Philips Hue) Light/Switch (TV-lamp)
2020-05-01 11:40:09.104 (Philips Hue) Color Switch (Toilet)
2020-05-01 11:40:09.172 (Philips Hue) Light/Switch (ZLLSwitch Ezra switch)
2020-05-01 11:40:09.184 (Philips Hue) Temp (Temperatuur Hue Bijkeuken)
2020-05-01 11:40:09.209 (Philips Hue) Light/Switch (ZLLPresence Motion sensor bijkeuken)
2020-05-01 11:40:09.236 (Philips Hue) Light/Switch (ZLLLightLevel Hue ambient light sensor 1)
2020-05-01 11:40:09.246 (Philips Hue) Lux (ZLLLightLevel Lux Hue ambient light sensor 1)
2020-05-01 11:40:09.269 (Philips Hue) Light/Switch (Geofence Samsung SM-G935F)
2020-05-01 11:40:09.293 (Philips Hue) Light/Switch (ZLLSwitch Woonkamer Switch)
2020-05-01 11:40:09.342 (Philips Hue) Light/Switch (ZLLPresence Motion sensor Toilet)
2020-05-01 11:40:09.369 (Philips Hue) Light/Switch (ZLLLightLevel Hue ambient light sensor 2)
2020-05-01 11:40:09.379 (Philips Hue) Lux (ZLLLightLevel Lux Hue ambient light sensor 2)
2020-05-01 11:40:09.392 (Philips Hue) Temp (Temperatuur Hue toilet)
2020-05-01 11:40:13.617 (Zonnepanelen 9) General/kWh (kWh Meter Inverter 9)
2020-05-01 11:40:13.638 (Zonnepanelen 9) General/Voltage (DC Inverter 1)
2020-05-01 11:40:13.668 (Zonnepanelen 9) Temp (SolarMain Inverter 1)
2020-05-01 11:40:13.681 (Zonnepanelen 9) General/Voltage (AC Inverter 1)
2020-05-01 11:40:13.695 (Zonnepanelen 9) General/Custom Sensor (Hz Inverter 1)
2020-05-01 11:40:13.882 (Thermosmart 11) Thermostat (Setpoint Thermosmart 11)
2020-05-01 11:40:13.911 (Thermosmart 11) Temp (Woonkamer temperatuur 11)
2020-05-01 11:40:13.935 (Thermosmart 11) Temp (outside temperature)
2020-05-01 11:40:13.953 (Thermosmart 9) Thermostat (Setpoint Thermosmart 9)
2020-05-01 11:40:13.979 (Thermosmart 9) Temp (Woonkamer temperatuur 9)
2020-05-01 11:40:13.998 (Thermosmart 9) Temp (outside temperature)
2020-05-01 11:40:13.687 Status: Thermosmart: Login successfull!...
2020-05-01 11:40:13.690 Status: Thermosmart: Login successfull!...
2020-05-01 11:40:14.016 (Thermosmart 9) Lighting 2 (Thermostat Pause)
2020-05-01 11:40:14.245 (Zonnepanelen 11) General/kWh (kWh Meter Inverter 11)
2020-05-01 11:40:14.258 (Zonnepanelen 11) General/Voltage (DC Inverter 1)
2020-05-01 11:40:14.274 (Zonnepanelen 11) Temp (SolarMain Inverter 1)
2020-05-01 11:40:14.283 (Zonnepanelen 11) General/Voltage (AC Inverter 1)
2020-05-01 11:40:14.292 (Zonnepanelen 11) General/Custom Sensor (Hz Inverter 1)
2020-05-01 11:40:14.920 Status: BuienRadar: Nearest station: Meetstation Woensdrecht (Woensdrecht), ID: 6340
2020-05-01 11:40:15.021 (Buienradar) Temp + Humidity + Baro (Buienradar)
2020-05-01 11:40:15.038 (Buienradar) Temp (Ground Temperature (10 cm))
2020-05-01 11:40:15.055 (Buienradar) Temp (Feel Temperature)
2020-05-01 11:40:15.071 (Buienradar) Wind (Wind)
2020-05-01 11:40:15.080 (Buienradar) General/Visibility (Visibility)
2020-05-01 11:40:15.099 (Buienradar) Rain (Rain)
2020-05-01 11:40:15.152 (Buienradar) General/Custom Sensor (Next Rainshower Leadtime)
2020-05-01 11:40:15.162 (Buienradar) General/Custom Sensor (Next Rainshower Duration)
2020-05-01 11:40:15.172 (Buienradar) General/Custom Sensor (Next Rainshower Avg Rainrate)
2020-05-01 11:40:15.181 (Buienradar) General/Custom Sensor (Next Rainshower Max Rainrate)
2020-05-01 11:40:15.192 (Buienradar) General/Percentage (Rain Intensity)
2020-05-01 11:40:15.211 (Buienradar) Lighting 2 (Possible Rain)
2020-05-01 11:40:15.221 (Buienradar) General/Custom Sensor (Rainfall next Hour)
Hue | Zigbee2Mqtt | MQTT | P1 | Xiaomi | RFXCom | Modbus | Qlima | Solaredge
TP-Link | Plugwise | Thermosmart | Node-Red | Grafana | Master and 5 remote servers
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 »

@Alain, my recent suggestion is not a plugin. It is a standalone Python script that can log HS110 information without using Domoticz. It has the advantage that it can send information to Domoticz as well. However, you need to add the hardware yourself in Domoticz:
* Use the 'Dummy - Does nothing, use for virtual switches only' type hardware.
* Once you have done that, click 'Create Virtual Sensors'.
* Name the first Device and select Voltage from the 'Sensor Type' list.
* Get your device Idx from the Devices tab and add that into the script. (The first number in domoticz_idx = [90,91,108,93]) Save and restart the script.
You should now see your mains voltage from the HS110 in Domoticz under Utility. Keep adding devices: Current, kWh and Switch

Good luck!

Cheers - Andrew
Alain
Posts: 166
Joined: Sunday 26 April 2020 5:27
Target OS: Linux
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: TP-Link smart plug HS100/HS110

Post by Alain »

Ahhh...thanks. I tried the script form a command prompt and it worked :)

I'll see how I go implementing it in Domoticz. Thanks for the tips.
Hue | Zigbee2Mqtt | MQTT | P1 | Xiaomi | RFXCom | Modbus | Qlima | Solaredge
TP-Link | Plugwise | Thermosmart | Node-Red | Grafana | Master and 5 remote servers
nosehook
Posts: 49
Joined: Thursday 31 March 2016 20:49
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: TP-Link smart plug HS100/HS110

Post by nosehook »

Hi There,

I rencently started my Domoticz setup from scratch again, after some issues with the OS upgrade.
Initially I started out with an old version of the plugin. This resulted in Error messagas, and a crash every 2.5 hours, however, my HS-110 info (watt, amps, etc) was updated as it should.

Yesterday I found out there is a new version of the plugin, so I installed that one. The result is no more errors, but also no more updates of the watts and amps.

Can anyone tell me how to fix the latter?

cheers
Pi3 Domoticz | RFXcom 433E | KAKU/COCO |Harmony Hub | Samsung TV | HS100 | HS110| HUE | Tradfri | Tado| Xiaomi |sensors | scripts| Pi3 Node Red | Pi2 SDS_011 + MH-Z19B | PiAware (zero) | Pi2 breadboard with Node red and Domoticz
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 @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
nosehook
Posts: 49
Joined: Thursday 31 March 2016 20:49
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: TP-Link smart plug HS100/HS110

Post by nosehook »

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
Hi Andrew,

The original plugin was this one:
Spoiler: show
# 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-e ... ink-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)))
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))

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
I did the update from: https://github.com/ajay10000/domoticz_hs110_plugin
The header looks like:

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
When looking at the debug log of one of the HS110's it shows:

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

Hope you can help me out. Cheers


edit: Just deleted all watt, volt and amp meters that were working preciously. The plugin created new ones, but all keep reading zero...
Pi3 Domoticz | RFXcom 433E | KAKU/COCO |Harmony Hub | Samsung TV | HS100 | HS110| HUE | Tradfri | Tado| Xiaomi |sensors | scripts| Pi3 Node Red | Pi2 SDS_011 + MH-Z19B | PiAware (zero) | Pi2 breadboard with Node red and Domoticz
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 »

@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.
nosehook
Posts: 49
Joined: Thursday 31 March 2016 20:49
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: TP-Link smart plug HS100/HS110

Post by nosehook »

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.
Hi Ajay100,

I am a bit confused what you want me to do.
I have set the log level to debug (everything) in settings>other. Despite that I do not see the line you refer to in the log. What I posted previously is all I get.

Do you want me to change things in line 137 and line 205?
Currently they read:
137: if self.heartbeatcounter % self.interval == 0:
205: if Parameters["Mode1"] in "HS110":

to clarify, I am running it as a plugin, 5 times, due to 2 x HS110 and 3x HS100. Switching on and off works, reading data doesn't.

I ahve just disables one and made a new one, still no data and also no log data about emeter


edit: after a reboot I did get data in the log:

2020-05-07 14:15:35.268 (Test) Device: 2-ID: 222, Name: 'Test - emeter current (A)', nValue: 0, sValue: ''
2020-05-07 14:15:35.269 (Test) Device Name: 'Test - emeter current (A)
2020-05-07 14:15:35.270 (Test) Device: 3-ID: 223, Name: 'Test - emeter voltage (V)', nValue: 0, sValue: ''
2020-05-07 14:15:35.270 (Test) Device Name: 'Test - emeter voltage (V)
2020-05-07 14:15:35.271 (Test) Device: 4-ID: 224, Name: 'Test - emeter power (W)', nValue: 0, sValue: ''
2020-05-07 14:15:35.272 (Test) Device Name: 'Test - emeter power (W)
2020-05-07 14:15:35.273 (Test) Creating device 'emeter current (A)'.
2020-05-07 14:15:35.274 (Test) Creating device 'emeter voltage (V)'.
2020-05-07 14:15:35.274 (Test) Creating device 'emeter power (W)'.
Pi3 Domoticz | RFXcom 433E | KAKU/COCO |Harmony Hub | Samsung TV | HS100 | HS110| HUE | Tradfri | Tado| Xiaomi |sensors | scripts| Pi3 Node Red | Pi2 SDS_011 + MH-Z19B | PiAware (zero) | Pi2 breadboard with Node red and Domoticz
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest