91JJ
(91JJ)
November 1, 2022, 4:55pm
1
I have the below binary sensor set up so that if it’s ‘ON’ - my light automations will run.
If OFF - light automations don’t run.
template:
- binary_sensor:
- name: light_automation_running
state: >
{% set use_sun = is_state('input_boolean.light_automation_times_use_sun', 'on') %}
{{ (now() <= today_at(states(iif(use_sun, 'sensor.sun_next_rise', 'input_datetime.lights_automation_lights_auto_on_before'))) or
now() >= today_at(states(iif(use_sun, 'sensor.sun_next_set', 'input_datetime.lights_automation_lights_auto_on_after'))) )}}
icon: >
{% if is_state("binary_sensor.light_automation_running", "on") %}
mdi:lightbulb-group
{% else %}
mdi:lightbulb-group-off
{% endif %}
This is connected to an input boolean which I can turn on to the the Sun Rise/Set times to turn ON/OFF the light automations.
So if the the Boolean is on, I manually set the times, otherwise it uses the sun rise/set times.
I’m now wanting to move this over to do two new functions
a new ‘Input Selector’ - to select what I want to trigger the light automations
Sun Rise/Set Times (as above)
Sun Elevation
Manual Times (as above)
The ‘Sun Elevation’ - To be able to adjust at what elevation
Input Selector
input_select.light_automation_trigger
Sun Elevation
input_number.light_automation_times_elevation
I’m struggling on
Converting the above code to look at the drop down list, rather than a on/off
How to set the elevation number.
Olivier1974
(Olivier Toussaint)
January 5, 2023, 7:26pm
2
If you look in the developer tools, you’ll see that the state of an input_select is the selected item
Therefore, you can do something like
{% if is_state("input_select.my_condition", "Sun elevation") %}
{# blabla bla #}
{% elif is_state("input_select.my_condition", "Sun Rise/Set Times") %}
{# blabla bla #}
{% else %]
{# blabla bla #}
{% end if %}
To “set the elevation number”, you just use your input_number in a card
To get the elevation, you use the state_attr function.
{% if state_attr('sun.sun',' elevation') < input_number.my_configuration %}
1 Like
91JJ
(91JJ)
January 6, 2023, 12:07pm
3
Thanks for this!
I had this in mind, just needed a steer.
Here is the full sensor if anyone is interested.
template:
- binary_sensor:
- name: light_automation_running_new
state: >
{% if is_state('input_select.light_automation_trigger', 'Manually Set (Start - Stop)') %}
{{ now() <= today_at(states('input_datetime.lights_automation_lights_auto_on_before')) or
now() >= today_at(states('input_datetime.lights_automation_lights_auto_on_after')) }}
{% elif is_state('input_select.light_automation_trigger', 'Sun Rise/Set') %}
{{ (now() <= today_at(states('sensor.sun_next_rise')) or now() >= today_at(states('sensor.sun_next_set')) )}}
{% elif is_state('input_select.light_automation_trigger', 'Horizon Elevation') %}
{{ state_attr('sun.sun','elevation') < states('input_number.light_automation_times_elevation') |float }}
{% elif is_state('input_select.light_automation_trigger', 'LUX') %}
{{ states('sensor.esp32_bedroom_lux') < states('input_number.lux') }}
{% endif %}
icon: >
{% if is_state('binary_sensor.light_automation_running_new', 'off') %}
mdi:lightbulb-group-off
{% elif is_state('input_select.light_automation_trigger', 'Manually Set (Start - Stop)') %}
mdi:emoticon-cool
{% elif is_state('input_select.light_automation_trigger', 'Sun Rise/Set') %}
mdi:sun-clock
{% elif is_state('input_select.light_automation_trigger', 'Horizon Elevation') %}
mdi:theme-light-dark
{% elif is_state('input_select.light_automation_trigger', 'LUX') %}
mdi:brightness-percent
{% endif %}
Final thing I’m trying to do, is have a custom icon for each state…
IF OFF = mdi:lightbulb-group-off
IF ON AND USING ;
Manual Set (Start - Stop) = mdi:emoticon-cool
Sun Rise/Set Times = mdi:sun-clock
Sun Elevation = mdi:theme-light-dark
LUX = mdi:brightness-percent
EDIT:
Code above updated for the icon