Use a specific attribute for a trigger or condondition

Hi guys,

I have a wemo insight switch that I am trying to use to trigger a notification so I know when an appliance is running. I have ended up with something overly complicated that doesn’t work. I simply want to get a notification when attribute current_power_w: is over a specified level. The trigger and notification work in other automation but when I add the condition I’m getting errors. What I have is

- alias: Sump pump is running
    platform: state
    entity_id: switch.wemo_insight
    state: 'on'
    - condition:
      platform: template
      value_template: '{{ is_state_attr('switch.wemo_insight.attributes.current_power_w > 30') }}' 
    - service: notify.joaoapps_join
        message: 'The sump pump is running.'

Any help is appreciated

Have you tried using

condition: template
value_template: '{{ states.switch.wemo_insight.attributes.current_power_w > '30' }}'


I am not sure if you should use single or double quotes, though.

@WonderMoose For the quotes surrounding your template (you are using single quotes here) you can use single or double quotes. However, for the times when you need quotes inside the template you will need to use the opposite of the quotes surrounding the template. So you would need to change '30' to "30".

The single and double quotes are interchangeable but you have to be consistent with them. If you use single on the outside and single on the inside the compiler will end the template at the next single quote since thats what tells it that the template is done, and since its incomplete you will get an error… In your example it would think the template is {{ states.switch.wemo_insight.attributes.current_power_w >

@matust you can use a template trigger in your automation for this and @WonderMoose template should work fine once you change the quotes surrounding 30 to double quotes. Although I would make a few changes to it:
'{{ states.switch.wemo_insight.attributes.current_power_w | int > 30 }}' (assuming that attribute can be cast to an int value)

@WonderMoose @stunts1337 Thank you both for your input. stunts1337 your changes were the key. It worked perfectly in the template and allowed me to simplfy it and is running great now

For anyone else who comes across this thread this the the working alert.

- alias: 'ALERT: Sump pump is running'
    platform: template
    value_template: '{{ states.switch.wemo_insight.attributes.current_power_w | int > 100 }}'
    service: notify.joaoapps_join
      message: Sump pump is running

Thanks for clearing that out! Until now it has mostly been a hit/miss approach from me =)
Just for curiosity, what is the advantage in the | int > 30 ?

Good that you got it to work, but wasn’t this a good case for a numeric_state trigger?

This is what I use to trigger when my washing machine finished.

- alias: finished washing
    - platform: numeric_state
      entity_id: sensor.laundry_power_23_8
      below: 2.0
    - service: notify.pushover
        title: "HASS"
        message: "washing machine just finished"

I’m not sure what sensor you are using but with the wemo insight the figure I needed was in the attributes and was not a state so is mixed in with a whole other lot of figures. I had tried using below: when attempting other templates but this solution works well without it.

The | int casts the value to an integer object, which will directly compare with 30 which is also an integer object (when not surrounded by quotes).

I think the value before that is a string. If that is so, when you compare it to "30" surrounded in quotes like that you are comparing strings, not numerical value. In this case it should still work because of their ascii values but it isn’t doing what you think it is doing.