TP-Link smart plug HS100/HS110
Moderator: leecollings
-
- Posts: 5
- Joined: Friday 23 February 2018 14:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: TP-Link smart plug HS100/HS110
Thanks,
it's working with the suggested changes .
it's working with the suggested changes .
-
- 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
Hello all, I have added a version here: https://github.com/ajay10000/TP-Link-HS110 (edited to correct link 2020-09-26)
This version supports sending data to Domoticz at set intervals and also direct commands. It also supports text logging.
Thanks for all the input in this forum, which has helped me to achieve what I wanted with the HS110.
Cheers - Andrew
This version supports sending data to Domoticz at set intervals and also direct commands. It also supports text logging.
Thanks for all the input in this forum, which has helped me to achieve what I wanted with the HS110.
Cheers - Andrew
Last edited by ajay100 on Saturday 26 September 2020 2:55, edited 2 times in total.
-
- Posts: 65
- Joined: Monday 21 August 2017 19:52
- Target OS: Windows
- Domoticz version: 3.8153
- Location: Rhoon
- Contact:
Re: TP-Link smart plug HS100/HS110
I'm a bit stuck here....Hope you can help me out. I had a script running for my HS110 perfectly for months. Had an issue with a memory card going bust and the back-ups weren't actually back-ups....
Now I'm puzzling everything back together but hit a wall here. I know I had a script running with which I could toggle the switch on/off (and I think that I also saw the state change when doing the switching on the HS110 itself) and I got the report back from usage.
Now I see at least three or four different solutions and getting stuck. I have the switching on/off working now with the code from https://github.com/softScheck/tplink-sm ... artplug.py
Works fine as a virtual switch, using "script://tplink_smartplug.py -t <HS110 IP address> -c on"
I can also get current energy with the "./tplink_smartplug.py -t <HS110 IP> -j '{"emeter":{"get_realtime":{}}}' command, but how on earth am I going to get this into Domoticz Virtual Switch?
Also looked at the code from ajay100, but there I need to fill in 3 IDx numbers....But have only 1 for energy.
Now I'm puzzling everything back together but hit a wall here. I know I had a script running with which I could toggle the switch on/off (and I think that I also saw the state change when doing the switching on the HS110 itself) and I got the report back from usage.
Now I see at least three or four different solutions and getting stuck. I have the switching on/off working now with the code from https://github.com/softScheck/tplink-sm ... artplug.py
Works fine as a virtual switch, using "script://tplink_smartplug.py -t <HS110 IP address> -c on"
I can also get current energy with the "./tplink_smartplug.py -t <HS110 IP> -j '{"emeter":{"get_realtime":{}}}' command, but how on earth am I going to get this into Domoticz Virtual Switch?
Also looked at the code from ajay100, but there I need to fill in 3 IDx numbers....But have only 1 for energy.
-
- 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
@Mace, with my modified code you can send a command directly to the HS110. For example, with the script uploaded to ~/domoticz/scripts/python and the correct permissions set, you can then try:
Response:
Sent: {"system":{"set_relay_state":{"state":0}}}
Received: {"system":{"set_relay_state":{"err_code":0}}}
Response:
Sent: {"system":{"set_relay_state":{"state":1}}}
Received: {"system":{"set_relay_state":{"err_code":0}}}
I added the HS110 hardware in Domoticz as 'Dummy (Does nothing, use for virtual switches)'
Then I added three virtual sensors (Create Virtual Sensors):
1. Voltage
2. Ampere (1 phase)
3. Electric (Instant + Counter)
In the code block that is the order for the array
The following line of code sets the array for the indexes retrieved from the Domoticz devices, (in the same order): (use your own indexes here). You can change the order or leave any out that you wish, provided your indexes from Domoticz match the corresponding virtual sensor.
Following your question, I then added a fourth virtual sensor, 'Switch'. I edited the 'on' action to:
and the 'off' action to:
[EDIT] Note that I didn't change the code at all for the switch to work, I just added the switch device to Domoticz. i.e. It doesn't require the index of the switch in the array.
I hope this helps, but let me know if you have any further questions.
Cheers - Andrew
[EDIT] PS: If you have more than one HS110 you could duplicate the script to a new name (i.e. tplink_hs110-2.py) and modify the logger_name, domoticz_idx and hs110_ip variables. You would then add another switch and change (for example) the 'on' action to
Code: Select all
cd ~/domoticz/scripts/python
python tplink_hs110.py -c off
Sent: {"system":{"set_relay_state":{"state":0}}}
Received: {"system":{"set_relay_state":{"err_code":0}}}
Code: Select all
python tplink_hs110.py -c on
Sent: {"system":{"set_relay_state":{"state":1}}}
Received: {"system":{"set_relay_state":{"err_code":0}}}
I added the HS110 hardware in Domoticz as 'Dummy (Does nothing, use for virtual switches)'
Then I added three virtual sensors (Create Virtual Sensors):
1. Voltage
2. Ampere (1 phase)
3. Electric (Instant + Counter)
In the code block
Code: Select all
# Begin user editable variables
Code: Select all
monitor_list = ["voltage","current","kwhr"]
Code: Select all
domoticz_idx = [90,91,93]
Following your question, I then added a fourth virtual sensor, 'Switch'. I edited the 'on' action to:
Code: Select all
script:///home/pi/domoticz/scripts/python/tplink_hs110.py -c on
Code: Select all
script:///home/pi/domoticz/scripts/python/tplink_hs110.py -c off
I hope this helps, but let me know if you have any further questions.
Cheers - Andrew
[EDIT] PS: If you have more than one HS110 you could duplicate the script to a new name (i.e. tplink_hs110-2.py) and modify the logger_name, domoticz_idx and hs110_ip variables. You would then add another switch and change (for example) the 'on' action to
Code: Select all
script:///home/pi/domoticz/scripts/python/tplink_hs110-2.py -c on
-
- Posts: 65
- Joined: Monday 21 August 2017 19:52
- Target OS: Windows
- Domoticz version: 3.8153
- Location: Rhoon
- Contact:
Re: TP-Link smart plug HS100/HS110
Thanks Andrew,
Seems to work fine now! Now just find out if you can get the state (on or off) reported, as now there can be a mismatch between domoticz and the actual status of the device if turned on or off manually....
Seems to work fine now! Now just find out if you can get the state (on or off) reported, as now there can be a mismatch between domoticz and the actual status of the device if turned on or off manually....
-
- 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
@Mace, apologies for not including the missing link. I am using the systemctl daemon on my Raspberry Pi for all scripts that I create. It starts the scripts at boot time and can be used to control them (i.e. start, stop, restart, status). This is how I set it up:
Create the service:
Paste in the following (modify path/name as required)
Save the new service (In nano, the keys are Ctrl-X, Y, Enter)
Make it executable:
Reload systemctl:
Enable the new service:
To check if the service is running:
If you change the code, restart the service:
I have used this now for all of my python scripts and it is helpful for me that I can use consistent commands.
Andrew
[EDIT] PS: It seems that you edited your question as I was responding, so this post doesn't answer your question!
Create the service:
Code: Select all
sudo nano /lib/systemd/system/tplink_hs110.service
Code: Select all
[Unit]
Description=Python script monitors TP-Link HS110 smart switch
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python /home/pi/domoticz/scripts/python/tplink_hs110.py -c energy
[Install]
WantedBy=multi-user.target
Make it executable:
Code: Select all
sudo chmod 644 /lib/systemd/system/tplink_hs110.service
Code: Select all
sudo systemctl daemon-reload
Code: Select all
sudo systemctl enable tplink_hs110.service
Code: Select all
sudo systemctl status -l tplink_hs110
Code: Select all
sudo systemctl restart tplink_hs110
Andrew
[EDIT] PS: It seems that you edited your question as I was responding, so this post doesn't answer your question!
-
- 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
Yes, I was thinking along the same lines and will need to put some further thought into that. I will possibly modify the script, or create a new interrogating script.
-
- Posts: 65
- Joined: Monday 21 August 2017 19:52
- Target OS: Windows
- Domoticz version: 3.8153
- Location: Rhoon
- Contact:
Re: TP-Link smart plug HS100/HS110
You are the man!!!! That would be awesome....
-
- Posts: 65
- Joined: Monday 21 August 2017 19:52
- Target OS: Windows
- Domoticz version: 3.8153
- Location: Rhoon
- Contact:
Re: TP-Link smart plug HS100/HS110
Thanks again, I tried it with a crappy cronjob, all I know....This helped me a lot and learned me a better way to do it.ajay100 wrote: ↑Monday 06 August 2018 15:29 @Mace, apologies for not including the missing link. I am using the systemctl daemon on my Raspberry Pi for all scripts that I create. It starts the scripts at boot time and can be used to control them (i.e. start, stop, restart, status). This is how I set it up:
[EDIT] PS: It seems that you edited your question as I was responding, so this post doesn't answer your question!
With cronjob's you can set intervals on when it runs, how does this work?
-
- 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
cronjobs work well for scheduling applications. In my case I want the app running all the time, capturing data at the time intervals set in the code
15 seconds is probably too frequent but sometimes you need to capture peaks and the shorter times make that more likely. If you would like hourly readings, use 3600, etc.
I am trying to find the command to get the relay status of the HS110. Does anyone know? I'm guessing something like but that didn't work.
[EDIT] Or
That didn't work either, but I found the correct command (see my next posts).
Code: Select all
delay_time = 15 #update time in seconds
I am trying to find the command to get the relay status of the HS110. Does anyone know? I'm guessing something like
Code: Select all
{"system":{"get_relay_state":{}}}
[EDIT] Or
Code: Select all
{"system":{"get_sysinfo":{"relay_state"}}}
Last edited by ajay100 on Saturday 11 August 2018 5:29, edited 1 time in total.
-
- Posts: 18
- Joined: Thursday 13 August 2015 4:36
- Target OS: Windows
- Domoticz version:
- Contact:
Re: TP-Link smart plug HS100/HS110
I've got a related question
Version: 4.9700
Build Hash: a3a45906
Compile Date: 2018-06-23 07:24:51
dzVents Version: 2.4.6
Python Version: 3.4.2 (default, Oct 19 2014, 14:03:53) [GCC 4.9.1]
I currently have several tplink smart plugs going with domoticz using the standard tplink_smartplug.py script
https://github.com/softScheck/tplink-sm ... artplug.py
Works great to turn on and off switches, but my switches can be run by alexa, kasa, and domoticz. So domoticz doesn't know when I use one of the other interfaces and then the status gets off (domo can say "off" when it is actually "on").
What I would like to do is update the switches with relay state (another virtual switch, or other means if there are better ideas). So far I can see the relay state by running
python ~./tplink_smartplug.py -t <ip> -c info
this returns a list of items, one of which if relay_state:0
Question is how do I use this to update my device status?
Version: 4.9700
Build Hash: a3a45906
Compile Date: 2018-06-23 07:24:51
dzVents Version: 2.4.6
Python Version: 3.4.2 (default, Oct 19 2014, 14:03:53) [GCC 4.9.1]
I currently have several tplink smart plugs going with domoticz using the standard tplink_smartplug.py script
https://github.com/softScheck/tplink-sm ... artplug.py
Works great to turn on and off switches, but my switches can be run by alexa, kasa, and domoticz. So domoticz doesn't know when I use one of the other interfaces and then the status gets off (domo can say "off" when it is actually "on").
What I would like to do is update the switches with relay state (another virtual switch, or other means if there are better ideas). So far I can see the relay state by running
python ~./tplink_smartplug.py -t <ip> -c info
this returns a list of items, one of which if relay_state:0
Question is how do I use this to update my device status?
-
- 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
Reading back through this thread, MikeF suggested the answer way back:
@punter9 and @Mace, there will probably be another virtual 'state' switch to check for the HS1XX before taking other actions.
[EDIT] No need to add another switch after all.
Cheers - Andrew
Code: Select all
relay_state = jsonData['system']['get_sysinfo']['relay_state']
[EDIT] No need to add another switch after all.
Cheers - Andrew
Last edited by ajay100 on Saturday 11 August 2018 8:07, edited 1 time in total.
-
- 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
I have updated the code https://github.com/ajay10000/TP-Link-HS110 to provide relay (switch) state feedback to the existing HS110 switch device in Domoticz.
track_state and hs110_switch_idx user variables are added. If track_state is True, the switch with hs110_switch_idx in Domoticz is updated at approximately delay_time intervals.
This may not be ideal if you have set a long update interval. In my case, the status is updated every 15 seconds.
Andrew
track_state and hs110_switch_idx user variables are added. If track_state is True, the switch with hs110_switch_idx in Domoticz is updated at approximately delay_time intervals.
This may not be ideal if you have set a long update interval. In my case, the status is updated every 15 seconds.
Andrew
-
- 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
In this version you will see four Domoticz index values as I have added another Custom Sensor device to measure power only. I'm using the HS110 to measure and log maximum and minimum power for various devices. The kWHr Domoticz device only shows power in watts for 24 hours, then for historical logging it only keeps the daily usage in kWHr.
For example, logging my new ASUS TM-AC1900 router and wireless internet antenna for 12 hours shows average power of around 10.5W with peaks just over 11W and a minimum of 10.1W. this is much more consistent than I would have expected. These are useful things to know when living off the grid.
Andrew
For example, logging my new ASUS TM-AC1900 router and wireless internet antenna for 12 hours shows average power of around 10.5W with peaks just over 11W and a minimum of 10.1W. this is much more consistent than I would have expected. These are useful things to know when living off the grid.
Andrew
-
- Posts: 18
- Joined: Thursday 13 August 2015 4:36
- Target OS: Windows
- Domoticz version:
- Contact:
Re: TP-Link smart plug HS100/HS110
I'm getting so close, I have a couple questions in the user editable variables.
# Begin user editable variables
base_url = domain + "json.htm?type=command¶m=udevice&nvalue=0"
-do I need to do anything here??
monitor_list = ["voltage","current","power","usage"]
domoticz_idx = [90,91,108,93]
-what do I do with these IDX? Do I create 4 switches in domoticz for each of the above "voltage","current","power","usage" and then plug the IDX into this line? If so what kind of switches?
hs110_switch_idx = 107
-is this for the on/off functionality?
# End user editable variables
# Begin user editable variables
base_url = domain + "json.htm?type=command¶m=udevice&nvalue=0"
-do I need to do anything here??
monitor_list = ["voltage","current","power","usage"]
domoticz_idx = [90,91,108,93]
-what do I do with these IDX? Do I create 4 switches in domoticz for each of the above "voltage","current","power","usage" and then plug the IDX into this line? If so what kind of switches?
hs110_switch_idx = 107
-is this for the on/off functionality?
# End user editable variables
-
- Posts: 18
- Joined: Thursday 13 August 2015 4:36
- Target OS: Windows
- Domoticz version:
- Contact:
Re: TP-Link smart plug HS100/HS110
I think I may have sorted out the 4 switches to make from above, not counting the on off switch. Now when i execute the script for commands that aren't on/off/info I get
File "tplink_hs110_latest.py", line 238, in <module>
hs.read_hs110()
File "tplink_hs110_latest.py", line 224, in read_hs110
self.send_json(received_data)
File "tplink_hs110_latest.py", line 155, in send_json
voltage = round(float(json_data['emeter']['get_realtime']['voltage_mv']) / 1000,2)
KeyError: 'emeter'
File "tplink_hs110_latest.py", line 238, in <module>
hs.read_hs110()
File "tplink_hs110_latest.py", line 224, in read_hs110
self.send_json(received_data)
File "tplink_hs110_latest.py", line 155, in send_json
voltage = round(float(json_data['emeter']['get_realtime']['voltage_mv']) / 1000,2)
KeyError: 'emeter'
-
- Posts: 10
- Joined: Sunday 25 January 2015 16:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: TP-Link smart plug HS100/HS110
Hiajay100 wrote: ↑Sunday 12 August 2018 3:03 In this version you will see four Domoticz index values as I have added another Custom Sensor device to measure power only. I'm using the HS110 to measure and log maximum and minimum power for various devices. The kWHr Domoticz device only shows power in watts for 24 hours, then for historical logging it only keeps the daily usage in kWHr.
For example, logging my new ASUS TM-AC1900 router and wireless internet antenna for 12 hours shows average power of around 10.5W with peaks just over 11W and a minimum of 10.1W. this is much more consistent than I would have expected. These are useful things to know when living off the grid.
Andrew
I am looking to get the hs100 unit to my domoticz setup. (dont have any need for energy messurment).
I have been reading and was wondering if your new script works for the hs100, or only for the 110? I would like to have the status reported back so domoticz and reality dont get "missmatched".
/KG
-
- 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
@punter9 base_url can stay the same. I've described adding the 4 devices (these are not switches) in my post of 06 August 2018 (above). hs110_switch_idx is the index of the virtual switch in Domoticz, for the switching function of the HS1xx.punter9 wrote: ↑Monday 03 September 2018 5:44 I'm getting so close, I have a couple questions in the user editable variables.
# Begin user editable variables
base_url = domain + "json.htm?type=command¶m=udevice&nvalue=0"
-do I need to do anything here??
monitor_list = ["voltage","current","power","usage"]
domoticz_idx = [90,91,108,93]
-what do I do with these IDX? Do I create 4 switches in domoticz for each of the above "voltage","current","power","usage" and then plug the IDX into this line? If so what kind of switches?
hs110_switch_idx = 107
-is this for the on/off functionality?
# End user editable variables
In Domoticz, the switch has these actions, also described in the above post:
On action: script:///home/pi/domoticz/scripts/python/tplink_hs110.py -c on
Off action: script:///home/pi/domoticz/scripts/python/tplink_hs110.py -c off
Andrew
-
- 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
@punter9, can you post the command you are executing? This error could also be caused by older firmware. If in doubt, turn full debugging on: debug_level="DEBUG" and see what the log file shows.punter9 wrote: ↑Monday 03 September 2018 6:38 I think I may have sorted out the 4 switches to make from above, not counting the on off switch. Now when i execute the script for commands that aren't on/off/info I get
File "tplink_hs110_latest.py", line 238, in <module>
hs.read_hs110()
File "tplink_hs110_latest.py", line 224, in read_hs110
self.send_json(received_data)
File "tplink_hs110_latest.py", line 155, in send_json
voltage = round(float(json_data['emeter']['get_realtime']['voltage_mv']) / 1000,2)
KeyError: 'emeter'
Andrew
-
- 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
@eriksson25, even though this is overkill for the HS100, it should work. If you issue the commands from Domoticz for off/on, it will not run in the loop that does the logging. However the catch is that the feedback does require the loop, so I would think that a stripped down version is required.
Andrew
Andrew
Who is online
Users browsing this forum: No registered users and 1 guest