Being new to this and coming over from the MagicMirror2 project I’m trying to learn to write my own automations.
I have searched through the forums and have found bits and pieces and they are great but I still cannot get my automation to work for some reason. Here is two examples of what I’ve tried. Can anyone please give me some insight to why they aren’t working, I appreciate the input!!
- alias: '13 - Turn on Light[s] on at sunset'
id: Turn on Light[s] on at sunset
trigger:
- platform: state
entity_id: device_tracker.john_s_galaxy_note20_ultra_5g
from: 'not_home'
to: 'home'
action:
service_template: light.turn_{{ 'on' if is_state('sun.sun', 'below_horizon') else 'off' }}
entity_id: light.livingroom1
2nd way:
#- alias: '13 - Turn on light[s] on sunset'
# id: Turn on light[s] on sunset
# trigger:
# - platform: state
# entity_id: sun.sun
# from: below_horizon
# to: above_horizon
# condition:
# condition: state
# entity_id: device_tracker.john_s_galaxy_note20_ultra_5g
# state: 'home'
# action:
# service: light.turn_on
# entity_id: light.livingroom1
Your automation should work fine. What’s not working about the automation? Also, as @123 said, inline if statements work just fine. So there is no difference between your code and @callifo’s.
My guess is that you have a minor typo in one of the entity_id names or sun.sun isn’t integrated into the system.
This what I came up with but it’s not turning on the light… but sensor.elevation is showing for example 7.5 ° I’m thinking the degree symbol may be the problem. Not really sure I’ve tried the above 2 and that makes 3 automations and none of them are working…LOL…oh new guys.
Yes its the entry called “Logbook” in the sidebar of the main overview screen in the web interface… very handy for seeing if your trigger is even working