Help with a automation

No matter if the value_template == true of false the automation completes.
I thought all conditions had to == true or the automation would stop.

Thanks


#automation:

  • id: ‘sprinkler_zone_front_am’
    alias: ‘[Sprinkler] Zone Front AM’
    trigger:
    • platform: template
      value_template: ‘{{ states(’‘sensor.time’’) == states(’‘input_datetime.sprinkler_zone_front_am_on_time’’).rsplit(’’:’’,1)[0]
      }}’
      condition:
    • condition: state
      entity_id: binary_sensor.sprinkler_zone_front_day_active
      state: ‘on’
    • condition: template
      value_template: “{{ states(‘sensor.nws_current_rain_forecast’) | int < states(‘input_number.front_percent_rain’) | int }}”
    • condition: not
      conditions:
      • condition: state
        entity_id: sensor.nws_current_condition
        state: ‘rainy’
      • condition: state
        entity_id: sensor.nws_current_condition
        state: ‘stormy’
      • condition: state
        entity_id: sensor.nws_current_condition
        state: ‘thunderstorms’
        action:
    • data:
      entity_id: script.sprinkler_zone_front
      service: script.turn_on

Can you repost using the code tags ( </> ) please.

The way it’s currently formatted it looks like you have conditions as triggers which can’t be right.

Sorry I don’t understand what you want…

< before code and > after? I thought it wanted

#automation:
- id: 'sprinkler_zone_front_am'
  alias: '[Sprinkler] Zone Front AM'
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == states(''input_datetime.sprinkler_zone_front_am_on_time'').rsplit('':'',1)[0]
     }}'
  condition:
  - condition: state
    entity_id: binary_sensor.sprinkler_zone_front_day_active
    state: 'on'
  - condition: template
    value_template: "{{ states('sensor.nws_current_rain_forecast') | int < states('input_number.front_percent_rain') | int }}"
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.nws_current_condition
        state: ‘rainy’
      - condition: state
        entity_id: sensor.nws_current_condition
        state: ‘stormy’
      - condition: state
        entity_id: sensor.nws_current_condition
        state: ‘thunderstorms’
  action:
  - data:
      entity_id: script.sprinkler_zone_front
    service: script.turn_on

Sorry

1 Like

Oh and the condition: template value_template “rain forecast” is the non working part

What is the output if you paste that template into the Developer Tools - Template page ?

“True” or “False” depending on the > or <. as is it’s “False” with < but the automation completes either way.

I’ve run into situations in which I had to explicitly define the result as true or false. I never figured out why that was needed on some but not all.

try this and see if it works:

- condition: template
    value_template: >
      {% states('sensor.nws_current_rain_forecast') | int < states('input_number.front_percent_rain') | int %}
        true
      {% else %}
        false
      {% endif %}

That still didn’t work, I thought it may because that got rid of the quotes… went from “false” to false.

Wait that did work… automation must have not reloaded when I first tried it.

Thanks

No it seemed like it worked…but it didn’t.

I’m confused…

How do you know for sure it’s the template causing the issue? Are you sure it’s not the other conditions?

What do you mean by “it seemed like it worked”? I would think it would be obvious that the actions ran or not.

the other thing I see is that in your code you have places where you have the “fancy” type quotes nit the plain text ones:

- condition: state
  entity_id: sensor.nws_current_condition
  state: ‘stormy’ <---these

instead of:

- condition: state
  entity_id: sensor.nws_current_condition
  state: 'stormy' <---these

When I reduce the code to only this

  alias: '[Sprinkler] Zone Front AM'
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == states(''input_datetime.sprinkler_zone_front_am_on_time'').rsplit('':'',1)[0]
     }}'
  condition:
  - condition: template
    value_template: >
      {% if states('sensor.nws_current_rain_forecast') | int < states('input_number.front_percent_rain') | int %}
        true
      {% else %}
        false
      {% endif %}
  action:
  - data:
      entity_id: script.sprinkler_zone_front
    service: script.turn_on

It still completes the automation with the condition: template either == true or false.
I didn’t realize there were “fancy” quotes and non “fancy”, I thought I just used the single quote.

I did replace the quotes, I must have copied them from somewhere.

If the condition: template = false. Should it not stop the automation, mean not run the script.turn_on?

BTW it always runs… I can’t make it not run when the condition: template = false.

yes, if false then the script shouldn’t run.

try this as a test:

alias: '[Sprinkler] Zone Front AM'
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == states(''input_datetime.sprinkler_zone_front_am_on_time'').rsplit('':'',1)[0]
     }}'
  condition:
  - condition: template
    value_template: >
      {{ false }}
  action:
  - data:
      entity_id: script.sprinkler_zone_front
    service: script.turn_on

The action shouldn’t run.

I got it working last night, strange how I got it working tho.
I tried everything even restarting the HA.
I have 4 of the same automation (Front AM, Front PM, Back AM, Back PM) and seems I had gotten most of the weather part added to the automation and my slider was the only thing not working, I copied what I had to the other 3 automations. As I was trying everything to get it working, after I added the code to the other 3 automations, I tried the Back PM automation… and it worked! So I went back through the other 3 and they all worked, even the Front AM one I had been trying that didn’t work before. I have no clue what kicked in into working.

Thanks for all your help… I may go back and remove the tire and false just to see if it works as I had in the beginning.

The code as it works now.

- id: 'sprinkler_zone_front_am'
  alias: '[Sprinkler] Zone Front AM'
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == states(''input_datetime.sprinkler_zone_front_am_on_time'').rsplit('':'',1)[0]
     }}'
  condition:
  - condition: state
    entity_id: binary_sensor.sprinkler_zone_front_day_active
    state: 'on'
  - condition: template
    value_template: >
      {% if states('sensor.nws_current_rain_forecast') | int < states('input_number.front_percent_rain') | int %}
        true
      {% else %}
        false
      {% endif %}
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.nws_current_condition
        state: ‘rainy’
      - condition: state
        entity_id: sensor.nws_current_condition
        state: ‘stormy’
      - condition: state
        entity_id: sensor.nws_current_condition
        state: ‘thunderstorms’
  action:
  - data:
      entity_id: script.sprinkler_zone_front
    service: script.turn_on
1 Like