First off I am new to HA and I apologize if there is already some amazing doc that I’ve missed that explains all this.
I am trying to use some basic if then else statements to include in my automation, I have one specifically that if motion is detected by one of my sensors do different things depending on the time of day. Now I currently have them using choose > conditions but just bypassing the visual editor and being able to write the code out seems easier, if I can ever figure it out.
So this is just an example but this first piece of code works as expected but the second one will not work.
alias: Test 234
variables:
variable1: Warning
description: ''
trigger:
Trigger here -
condition: []
action:
- service: notify.mobile_app_user_phone
data:
data:
priority: high
ttl: 0
message: "{{ variable1 }}"
title: Alert
As soon as I try to add an if condition the whole thing breaks, I’ve not been able to find any documentation on the exact logic or placement of the if condition but this exact code does work in the template section under dev tools
{% if is_state("sun.sun", "above_horizon") -%} ## also tried if states("sun.sun", here
{% set tod = {"type": "Shutdown_Day_Motion"} %}
{%- else -%}
{% set tod = {"type": "Shutdown_Night_Motion"} %}
{%- endif %}
alias: Test 234
description: ''
trigger:
Trigger here -
condition: []
action:
- service: notify.mobile_app_user_phone
data:
data:
priority: high
ttl: 0
message: "{{ tod.type}}"
title: Alert
Any help would be appreciated.