TPLINK HS110 switch, use energy consumption as sensor

Thanks @kirichkov, that’s a pretty neat bit of templating. :smiley:

Some of you maybe interested in voting for the auto-discovery feature request I just created to simplify your configuration.yaml:

I don’t know where you live, but in Europe prices are (including all type of taxes) in the 0,20 range (0,20Euro/KWh = 200 Euro/MWh

Guys, you recommend this plug? Does it sync well the state on/of? Considerin the price, this seems a good option to integrate with HA.

It does sync the state and the underlying library is actively maintained, so software-wise it’s a solid choice. BUT, I’ve encountered occasional crashes of the plug itself. It stops responding unless you remove it and re-add it. I think it gets worse if you have severe voltage drops. At a place where electricity was unstable I had to reconnect it every few hours. If the voltage was stable at 230-240V, crashes happen once every few months, which I’d consider acceptable given the price.

My choice was to go with Z-wave plugs, however. They are marginally more expensive in Europe, if you are on the lookout for the Amazon deals.

1 Like

I have a few of them, and they’ve worked flawless for me. So I’d recommend them :+1:t3:

1 Like

I like the plug, but I ran into an issue that I documented here:

I still like the plug, though, and it works reliably for me apart from the issue above which I learned to live with.

Tks for the feedback! Bought one to see how things go! Was a bit apprehensive with kirichkov comentary regarding the restart of the plug. Will give it a try for one month to see how things go.

I’ve also had the recomendation of a sonoff S20 with an firmware replacement, and since it’s quite cheaper I’m considering also buying one just to compare both and decide. In the majority of the plugs I have the monitoring is not that important.

Hi all,

I don’t know why but since few updates ago the template sensor doesn’t work.

If I click on the switch info I see all the infos (consuption etc) but none of them are avaible in the template sensor.

Here’s the code:

  - platform: template
    sensors: 
      tp_link_amps:
        value_template: '{{ states.switch.presa_smart.attributes["Current"] | replace(" A", "") | float }}'
        unit_of_measurement: 'A'
      tp_link_watts:
        value_template: '{{ states.switch.presa_smart.attributes["Current consumption"] | replace(" W", "") | float }}'
        unit_of_measurement: 'W'
      tp_link_kwd:
        value_template: '{{ states.switch.presa_smart.attributes["Daily consumption"] | replace(" kW", "") | float }}'
        unit_of_measurement: 'kW'
      tp_link_kwt:
        value_template: '{{ states.switch.presa_smart.attributes["Total consumption"] | replace(" kW", "") | float }}'
        unit_of_measurement: 'kW'
      tp_link_kwdh:
        value_template: '{{ states.switch.presa_smart.attributes["Daily consumption"] | replace(" kW", "") | float * 0.20}}'
        unit_of_measurement: '€'
      tp_link_volts:
        value_template: '{{ states.switch.presa_smart.attributes["Voltage"] | replace(" V", "") | float }}'
        unit_of_measurement: 'V'

Can someone please help me ?

Thank you in advance!

It was a breaking change is 0.55

TP-Link Switch: Attribute names now uses underscores and unnecessary capitalization was removed. (@djchen - #9607) (switch.tplink docs) (breaking change)

3 Likes

it worked! Thank you very much!

Hi, maybe I’m stupid but I can’t make my HS110 work since the last upgrades. The switch works and I can opperate it from HA, but I’cant see any values besides on/off.

So, in my sensors.yaml it looks like this:

  - platform: template
    name: Termo
    sensors:
    tp_link_amps:
      value_template: '{{ states.switch.termo.attributes["current"] | replace(" A", "") | float }}'
      unit_of_measurement: 'A'
    tp_link_watts:
      value_template: '{{ states.switch.termo.attributes["current_consumption"] | replace(" W", "") | float }}'
      unit_of_measurement: 'W'
    tp_link_kw:
      value_template: '{{ states.switch.termo.attributes["total_consumption"] | replace(" kW", "") | float }}'
      unit_of_measurement: 'kW'
    tp_link_volts:
      value_template: '{{ states.switch.termo.attributes["voltage"] | replace(" V", "") | float }}'
      unit_of_measurement: 'V'

and in the switch.yaml it looks like:

- platform: tplink
  host: !secret iptermo
  name: "Termo"

Also, the group is:

termo_info:
name: Termo
icon: mdi:hot-tub
view: yes
entities:
- group.Termo

Termo:
- sensor.tp_link_current_consumption
- sensor.tp_link_watts
- sensor.tp_link_kw
- sensor.tp_link_volts

I can’t find what is wrong with that

1 Like

The code looks exactly the same as mine (apart from I don’t hide the IP address in a separate file).

Not sure why it doesn’t work, maybe try adding the IP address there, or checking the link to the .yaml file containing the IP address, or even checking the smart plug still has that IP address?

Did you by any chance upgrade the firmware of the switch? I’ve seen people running firmware 2.0 on their switches, and firmware 2.0 is not compatible (yet) with the library that handles the communication with the switch. Load the Kasa app and check out the firmware version - 1.0.8 and I think 1.1.0 are known to work.

Just as an FYI: my HS110s are working fine on firmware version 1.2.2.

Nevermind, the plug wasn’t reporting to the app neither, so I restarted the plug and is working like a charm right now.

I’ve noticed that if the grid’s voltage is not stable and has sudden drops the switch becomes unresponsive until it’s restarted. Maybe that’s what happened in your case.

My “laundry started” and “laundry done” notification automations were working fine for months and then I noticed I stopped getting notifications. I checked and it was because my sensors stopped working. The sensors are just like Nelbu’s.

It the switch attribute I can see the instantaneous measurements, but the sensors aren’t showing anything. I’ve tried restarting the switch twice. My friend also has a TP-Link switch and noticed the same thing as me.

I am on firmware 1.0.8. It looks like the problem is the syntax of the switch itself. Can anyone with working sensors confirm if mine are correct?

sensor:
  - platform: template
    sensors:
      washingmachine_amps:
        value_template: '{{ states.switch.washing_machine.attributes["Current"] | replace(" A", "") | float }}'
        unit_of_measurement: 'A'
        friendly_name: 'Washing Machine'
      washingmachine_watts:
        value_template: '{{ states.switch.washing_machine.attributes["Current consumption"] | replace(" W", "") | float }}'
        unit_of_measurement: 'W'
        friendly_name: 'Washing Machine'
      washingmachine_kw:
        value_template: '{{ states.switch.washing_machine.attributes["Total consumption"] | replace(" kW", "") | float }}'
        unit_of_measurement: 'kW'
        friendly_name: 'Washing Machine'
      washingmachine_volts:
        value_template: '{{ states.switch.washing_machine.attributes["Voltage"] | replace(" V", "") | float }}'
        unit_of_measurement: 'V'
        friendly_name: 'Washing Machine'

A few versions ago the attribute names in the component changed to:
current_consumption
daily_consumption
total_consumption

Looks like this needs adjusting in your config.

1 Like

Thanks that worked!

Are you happy with the sensor? The kW meter seems legit?