Automation Trigger works without condition, but when condition added fails to work

Hi - this is probably my own stupid fault but… I have an automation which is designed to trigger when one numeric helper is greater than the other, PLUS (in the condition) a sensor state is set to zero. The automation triggers as expected when no sensor state condition is present, but when I add it, the automation no longer triggers. I have checked the sensor state using developer tools and it is set to 0.

I have tried various combinations of things but none seem to work. Would be very grateful for some pointers. I am still a novice!

description: ""
trigger:
  - platform: numeric_state
    entity_id: input_number.test_charge_percent
    above: input_number.required_battery_percentage
condition:
  - condition: template
    value_template: "{{ states( sensor.fronius_storctl_mod.state ) | int == 0 | int }}"
action:
  - service: notify.mobile_app_iphone_12_steve
    metadata: {}
    data:
      message: Test block charge
mode: single```

Do you need the second | int in the template?

condition:
  - condition: template
    value_template: "{{ (states('sensor.fronius_storctl_mod' ) | int) == 0 }}"

states('sensor.fronius_storctl_mod')

Untested as I am at work, but I think this is the correct syntax.

Correct, but that still returns a string.

All in all you do not need a template for this. A state condition would work equally well, and can be fully specified using the gui.

3 Likes

You need to put the | int back on it. I was just showing your error.

Thanks - initially I had it without the state but it didn’t work then either!

I’ll try that, thanks. Still odd as to why it doesn’t work as a template though, especially as I’m using the entire process as a huge learning exercise.

Right. But, you were missing the quotes.

states() takes in a string. The name of the object. Not the actual object.

I’ve tried what you suggested, Edwin, had to set the value to Be ‘< 1’ as there isn’t an ‘equals’ option, but that does work, thank you very much.

That is because you chose numeric state as the condition type, but you can also use state. That is the equals option, and also works on numerical values. A little unexpected, but once you know it is easy.

1 Like

That worked, thanks again Edwin. A bit counter-intuitive but really good to have this as a working example, learnt a lot.

1 Like