I have a problem with a simple automation I am attempting:
automation:
- alias: Bed 2 thermostat on at sunset
hide_entity: False
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: '{{ states.sun.sun.attribute.elevation }}'
below: 5.0
action:
service: switch.turn_on
entity_id: switch.thermostat_bedroom_2
- alias: Bed 2 thermostats off at sunrise
hide_entity: False
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: '{{ states.sun.sun.attributes.elevation }}'
above: 5.0
action:
service: switch.turn_off
entity_id: switch.thermostat_bedroom_2
I have used different above/below values today to try and trigger it but it doesn’t seem to work. Nothing happens. I have also tried using I’ve seen examples using either :
value_template: {sun.attribute.elevation }
I have sun enabled:
# Track the sun
sun:
and the correct Latitude Longitude for my location.
This is from the hass docs - it uses state.attributes.elevation rather than states.sun.sun.attribute.elevation and also uses double quotes not single quotes around the template
automation:
alias: "Exterior Lighting on when dark outside"
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: "{{ state.attributes.elevation }}"
# Can be a positive or negative number
below: -4.0
action:
service: switch.turn_on
entity_id: switch.exterior_lighting
The example from the docs was were I started jimbob1001. I tried with and without the hyphen before alias… Is it just me or is there a little mystery on these hyphens? I also tried the “{{ state.attributes.elevation }}”.
The one from the docs doesn’t seem to work for me.
However lambtho, I inserted your code and it also worked:
Another difference between the two approaches appears to be that the Template Trigger rechecks the > state if you restart Home Assistant and carries out the action again, whereas the Numeric State does not and only activates as you pass through the trigger. An expert could probably elaborate better, and shed light on pros and cons of each approach?
think a hyphen is required if you have more than one trigger in your automation - if you only have one trigger you shouldn’t need the hyphen, but in my experience it still works