TPLink attribute to sensor change

Hi there,

Im trying to update my automation code for the recent TPLink change that moved the vaules from attributes to sensors. I cant get my template sensor to hold a value and the template sensor just reads “Unavailable”. They should hold “True” or “False” depending on the current. The commented out code was my previously working code. I initially tried it without replacing the " W" but that doesn’t work either. Note, its not a typo, I used to monitor Watts.

 - platform: template
    sensors:
      #washing_machine:
      #  friendly_name: 'Washing Machine'
      #  value_template: '{{ states.switch.laundry_wm.attributes["current_power_w"] | replace(" W", "") | float > 1.5 }}'
      washing_machine:
        friendly_name: 'Washing Machine'
        value_template: "{{ state('sensor.laundry_wm_current') | replace(' A', '') | float > 2 }}"
      dryer:
        friendly_name: 'Dryer'
        value_template: "{{ state('sensor.laundry_dr_current') | replace(' A', '') | float > 2 }}"

Any help appreciated

Can you please go to Developer Tools / States, copy and paste the state and attributes of the following entities in a post here:

switch.laundry_wm
sensor.laundry_wm_current
sensor.laundry_dr_current

If you want to get a true or false, you can use binary_sensor.

For the other two, you should use-
states('sensor.laundry_wm_current')
You are missing a s

1 Like

Lol. The ‘s’. Thats it. All working now. Interestingly, this code was cut and paste from another “solution” I googled. Thanks for your help. Also, yes I should convert this to a binary sensor. These are the problems you have when you’ve had the same RPi2 running since HA 0.6x! :slight_smile:

Just an info, there’s a new modern format to create template sensor and template binary sensor. You can find it here-

The new format looks like this-

template:
  - binary_sensor:
      - name: "Washing Machine"
        state: >-
          {{ states('sensor.laundry_wm_current') | replace(' A', '') | float > 2 }}

The template format you use is now called legacy format. Although there are yet any plans to deprecate the old format, I personally think its better if you start using the modern format.