Is there any way to have a sun elevation trigger based on being below a input_number value?
bs_aalight_extlights_nightslot:
value_template: >
{% set elevation = state_attr('sun.sun', 'elevation') | float %}
{% set rising = state_attr('sun.sun', 'rising') %}
{% set nightstart = states('input_number.in_aalight_flood_on_elev_offset') | float %}
{% set nightstop = states('input_number.in_aalight_flood_off_elev_offset') | float %}
{{ (elevation <= nightstart and not rising) or (elevation <= nightstop and rising) }}
friendly_name: External Light Night Slot
icon_template: "{{ 'mdi:weather-night' }}"```
What context is that, an automation?
How would it fit into an automation like this?
automation:
alias: "Exterior Lighting on when dark outside"
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
# Can be a positive or negative number
below: -4.0
action:
service: switch.turn_on
entity_id: switch.exterior_lighting
Thatās a template binary sensor, so that you can then use the state of that directly. Youād just use it in a state trigger
trigger:
platform: state
entity_id: binary_sensor.bs_aalight_extlights_nightslot
to: 'on'
Apologies, I assumed you just needed the syntax to get an input number into a comparison.
As Tinkerer says you ācouldā use that as your trigger.
I do, as it concetrates processing in one template, so itās more efficient, it also allows a different morning elevation to an evening elevation, so is more flexible too
The the āautomationā only evaluates when the sensor changes state
To use your example : -
automation:
alias: "Exterior Lighting on when dark outside"
trigger:
platform: template
entity_id: sun.sun, input_number.in_aalight_flood_on_elev_offset
value_template: "{{ state_attr('sun.sun', 'elevation') | float <= states('input_number.in_aalight_flood_on_elev_offset') | float}}"
action:
service: switch.turn_on
entity_id: switch.exterior_lighting
You need to āReply Toā someone to get their attention, I only saw you responded āby accidentā
Thanks! Appreciate it.
Throwing an error āInvalid config for [automation]: [entity_id] is an invalid option for [automation]. Check: automation->trigger->0->entity_id. (See /config/configuration.yaml, line 446).
10:53:53 AM ā config.py (ERROR)ā
Hereās what Iām trying based on your example:
- alias: Coop Close Door Sunset
trigger:
platform: template
entity_id: sun.sun, input_number.sunset_delay
value_template: "{{ state_attr('sun.sun', 'elevation') | float <= states('input_number.sunset_delay') | float }}"
action:
- service: cover.close_cover
data:
entity_id: cover.coop_door
Edit: this works as a binary_sensor template, but not when an automation trigger.
Okay, Iām on my phone (now and then) so Iām doing this from memory.
Given the message then just comment out the entity_id: line (put a # at the beginning)
Or check the documentation on automation triggers.
Though taking a quick look, it looks like itās required, check the yaml spacing, remember yaml likes spacing in pairs
No, thereās no āentity_idā required for a template trigger.
Thanks for pointing that out.
The moral of the story is its difficult to read documentation on a phone
Shows how useless I am without access to my code and vsc