Binary sensor: Catch a specific power range of socket

Hi!

Guys I try to cath my washing machine’s power socket for some range of watts.

If watts is >2.9 and <3.3 it’s an error during washing.

I try this:

  - platform: template
    sensors:
      washing_machine_error:
        friendly_name: "Washing Machine Error sensor"
        delay_on:
          seconds: 10
        value_template: >-
          {{ states('sensor.bathroom_washing_machine_socket_power')|float(0) >= 2.9 }} and
          {{ states('sensor.bathroom_washing_machine_socket_power')|float(0) <= 3.3 }}

But seems it’s not working, 'coz when WM is stopped by error, I don’t have this binary sensor is on. Can someone help with it? Any ideas? How to catch error state.

And this one, >2.9 always is true, 'coz whem WM is start washing, watts is bigger than 2.9 anyway…

You need to include all the elements of the expression within a single pair of curly braces… otherwise, it will just print something like “true and false”… which will throw an error in a binary sensor.

  - platform: template
    sensors:
      washing_machine_error:
        friendly_name: "Washing Machine Error sensor"
        delay_on:
          seconds: 10
        value_template: >
          {{ 3.3 >= states('sensor.bathroom_washing_machine_socket_power')|float(0) >= 2.9 }}
1 Like

Wow, thanks, yes, I think about it, 'cuz I wanted only one condition for turn it on. I will try it and back some feedback. :+1:

With the modern configuration:

template:
  - binary_sensor:
      - name: Washing Machine Error
        state: "{{ 3.3 >= states('sensor.bathroom_washing_machine_socket_power')|float(0) >= 2.9 }}"
        delay_on:
          seconds: 10
4 Likes

Thanks guys! Yes, I will switched off to modern style now… I tested this state without working of washing machine seems it’s works as expected, so will wait for real case situation :smiley: