Then just look at the state of sensor.run_the_water_system being on.
so, just to let you know. now() gets the current time. now().weekday() gets the current weekday index based of monday equaling 0. So if we make a list of weekday names with monday being the first, then use the now().weekday() to pull out the name, we can then add the strings together to look at the current entity_id and extract the state.
EDIT:
Then in your automation, lets say you wanted to trigger the water every day at 5am:
- alias: Water the lawn
trigger:
- platform: time
at: '05:00:00'
condition:
contidion: state
entity_id: sensor.run_the_water_system
state: 'on'
action:
- service: .... etc....
I have tried to use your example and implement two ‘programs’ for my reticulation system but it fails the config verification. (once I get one program working I will duplicate for the second) This is what I have in my package:
reticulation.yaml
sensor:
- platform: template # determine if today is selected as a watering day for program 1
sensors:
retic_program1_watering_day:
value_template: >
{% sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
{% today_name = sensor_names[now().weekday()] %}
{% entity_id = 'input_boolean.retic_program1_'+today_name %}
{{ is_state(entity_id, 'on') }}
input_boolean:
retic_program1_monday:
name: Monday
retic_program1_tuesday:
name: Tuesday
retic_program1_wednesday:
name: Wednesday
retic_program1_thursday:
name: Thursday
retic_program1_friday:
name: Friday
retic_program1_saturday:
name: Saturday
retic_program1_sunday:
name: Sunday
sensor:
- platform: template # determine if today is selected as a watering day for program 1
sensors:
retic_program1_watering_day:
value_template: >
{% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
{% set today_name = sensor_names[now().weekday()] %}
{% set entity_id = 'input_boolean.retic_program1_'+today_name %}
{{ is_state(entity_id, 'on') }}
I just tried it in the template checker and it works, including changing state based on my input_booleans, so its looking good just waiting on a HA restart to confirm…
thank you so much @petro and @anon43302295, your code has worked perfectly. now I just need to complete the automations and duplicate for the two ‘programs’ and I’ll be done. greatly appreciated! I’ll post the final product in the original thread once its all done.
Template sensor 'retic_program1_watering_day' has no entity ids configured to track nor were we able to extract the entities to track from the value template(s). This entity will only be able to be updated manually.
- platform: template # determine if today is selected as a watering day for program 1
sensors:
retic_program1_watering_day:
entity_id: sensor.date #<---------------ADD THIS
value_template: >
{% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
{% set today_name = sensor_names[now().weekday()] %}
{% set entity_id = 'input_boolean.retic_program1_'+today_name %}
{{ is_state(entity_id, 'on') }}