HS300 support (sort of)

I have several HS300 wifi power strips that i have been holding off on deploying until they get added into HA. i know the backend is there, but someone needs to rework the HA python files. not being a python developer, i had to go with what i know. I know linux and shell scripting. so I wrote some scripts as a work around until proper support is added. I’m sharing in case anyone else finds this useful.

These are instructions for my setup, you will have to adapt to your specific setup.

  1. ensure pyhs100 is installed
    source /srv/homeassistant/bin/activate
    pip install pyhs100

  2. because the state and power usage for the entire strip is returned when called, i didn’t think it was very efficient to call for it for each individual plug. you get all of the same information each time.
    so what i did was - using node red, run a script at a determined interval (5 minutes in my case) to dump the stats of the power strip. this gives me the state of each one and the power usage for each one.
    I then parse that data and return it to HA via more scripts.

I call this script get_state.sh

 #!/bin/bash
/srv/homeassistant/bin/pyhs100 --host 192.168.2.240 --strip state > /home/hass/192.168.2.240.txt
/srv/homeassistant/bin/pyhs100 --host 192.168.2.241 --strip state > /home/hass/192.168.2.241.txt

this is ran every 5 minutes via node red.
i added this to shellcmds.yaml
wifistrip_status: /home/hass/get_state.sh

and use the HA node red integration to run it every 5 minutes. you can run it as much as you like. but typically super granular stats are not really needed in my case. so 5 minutes is fine.
if you are not using node red, then use your preferred method to run a shell script at whatever time interval you want.

now that we have the plug state and power usage for each power strip dumped. we then parse the data for each one in HA

  1. in sensor.yaml i have the following (i’m only posting the first 2, copy it up to 6)
- platform: command_line
  name: Net_Plug1
  command: "/home/hass/read_pwr.sh 192.168.2.240 plug1"
  unit_of_measurement: "W"
- platform: command_line  
  name: Net_Plug2
  command: "/home/hass/read_pwr.sh 192.168.2.240 plug2"
  unit_of_measurement: "W"

this reads the wattage for each plug into HA, it’s returned in MW, but i convert in the read_pwr.sh script. which looks like this…

#!/bin/bash
plug1=`cat /home/hass/$1.txt | awk -F'1:' '{print$1}' | tail -1 | cut -f3 -d, | cut -f2 -d: | awk '{print$1/1000}'`
plug2=`cat /home/hass/$1.txt | awk -F'2:' '{print$1}' | tail -1 | awk -F'1:' '{print$2}' |cut -f3 -d, | cut -f2 -d: | awk '{print$1/1000}'`
plug3=`cat /home/hass/$1.txt | awk -F'3:' '{print$1}' | tail -1 | awk -F'2:' '{print$2}' |cut -f3 -d, | cut -f2 -d: | awk '{print$1/1000}'`
plug4=`cat /home/hass/$1.txt | awk -F'4:' '{print$1}' | tail -1 | awk -F'3:' '{print$2}' |cut -f3 -d, | cut -f2 -d: | awk '{print$1/1000}'`
plug5=`cat /home/hass/$1.txt | awk -F'5:' '{print$1}' | tail -1 | awk -F'4:' '{print$2}' |cut -f3 -d, | cut -f2 -d: | awk '{print$1/1000}'`
plug6=`cat /home/hass/$1.txt | awk -F'5:' '{print$2}' | tail -1 | cut -f3 -d, | cut -f2 -d:| awk '{print$1/1000}'`
echo -e "plug1:$plug1\nplug2:$plug2\nplug3:$plug3\nplug4:$plug4\nplug5:$plug5\nplug6:$plug6\n" | grep $2 | cut -f2 -d:
  1. switches
    In switch.yaml we control each plug and get the state of each plug. (again only posting the 1st two. copy it up to 6)
- platform: command_line
  switches:
    netplug1:
      command_on: '/home/hass/too.sh 192.168.2.240 on 1'
      command_off: '/home/hass/too.sh 192.168.2.240 off 1'
      command_state: '/home/hass/read_state.sh 192.168.2.240 1'
      value_template: '{{ value == "ON" }}'
      friendly_name: Net Plug 1
    netplug2:
      command_on: '/home/hass/too.sh 192.168.2.240 on 2'
      command_off: '/home/hass/too.sh 192.168.2.240 off 2'
      command_state: '/home/hass/read_state.sh 192.168.2.240 2'
      value_template: '{{ value == "ON" }}'
      friendly_name: Net Plug 2

too.sh (turn on off) script looks like this

#!/bin/bash
/srv/homeassistant/bin/pyhs100 --host $1 --strip $2 $3

read_state.sh looks like this

#!/bin/bash
cat /home/hass/$1.txt | grep "Plug $2" | head -n 1 | cut -f2 -d:

I need to go back and name the plugs for what is connected to them (i.e. tv, xbox, etc) but this was just a proof of concept deal.
yes i know it’s ugly and hacky but it works.

5 Likes

thanks for sharing, this is what I need but home assistant in raspberry pi not allow to use the shell command, i’m wondering if there any install plugin by the add-ons store, many thanks

1 Like

What’s the current state of this device in HA? I’m considering replacing a dumb power strip in my media cabinet with one of these so I can monitor the consumption of my devices.

Are the USB Ports part of the energy monitoring? Does the strip report total energy usage, which would include the 6 outlets plus USB. Not like USB will be a lot or a dealbreaker, but kinda curious.

Is the data collected locally or through the cloud?

it works well now with HA integration. the USB ports are not part of power monitoring
it does report total daily consumption per plug, but you could easily build a sensor to combine all those
again usb not part of it.

the last question you will need to search on. I have version 1 of the firmware and never upgraded I do think they may have taken local control away with an update, but you’ll need to look into that to confirm.

Thank you. Is the model still the same, just different version? Don’t see a lot of threads about this unit here.

If anyone else sees this, do you have local control with newer firmware versions?

same model. here is the link. I’m not sure if it’s applies to the hs300 or not
https://community.tp-link.com/en/smart-home/forum/topic/239364

1 Like

Thank you!

I got an HS300 from NewEgg. It’s V2 and is running firmware 1.0.3. I declined a firmware upgrade.

I can see this in HA and it reports current/power every few seconds. Based on packet captures done at my router level, it doesn’t seem to be doing it locally, but it appears to work over the cloud.

Port 9999 is open, so I might be able to get this to work with local control, as long as I never update the firmware.

I have V1 with firmware 1.0.6
it does try to phone home or something, but i blocked that at the DNS level.
local control works for my setup. glad i never took the updates. works fine the way it is.

I was having issues with the energy consumption numbers from my HS300 v2 on firmware 1.03. The voltage and current values were super high which made the consumption values ridiculously high.

Values on 1.0.3 when polling with python-kasa:

== Current State ==
EmeterStatus power=17691.48 voltage=223.196 current=142.367 total=794.646

After updating to the latest 1.0.12

== Current State ==
EmeterStatus power=197.209 voltage=118.48 current=2.077 total=0.0