I’m trying to set up a template that will only show the percentage based on the time.
IF between “AM Start” and “AM End” = display 20%
IF between “PM Start” and “PM End” = display 55%
Else = Display 100%
and create one sensor to determine if you are in AM for example. You display the required card (using two conditional cards) if the state of the sensor is “on” (AM card) or “off” (PM Card)…
Personally I would make this a binary sensor so that it would be on/off and that should then control the conditional card.
Doing the templating past midnight would be to much work for me.
If you just have the yaml I wrote then it will be true at daytime and false at night, that is enough for your conditional card.
No need to make two binary sensors.
I’m wanting to use those to create a Template Binary Sensor which will show the % based off the am/pm times.
AM : {{ states('input_number.lights_brightness_am') }}%
{{ states('input_datetime.lightautomation_am_bri_start') }}
{{ states('input_datetime.lightautomation_am_bri_end') }}
PM : {{ states('input_number.lights_brightness_pm') }}%
{{ states('input_datetime.lightautomation_pm_bri_start') }}
{{ states('input_datetime.lightautomation_pm_bri_end') }}
Time Now: {{now().hour }}:{{now().minute}}
AM % : {{ now() >= today_at(states('input_datetime.lightautomation_am_bri_start')) or
now() <= today_at(states('input_datetime.lightautomation_am_bri_end')) }}
PM % : {{ now() >= today_at(states('input_datetime.lightautomation_pm_bri_start')) or
now() <= today_at(states('input_datetime.lightautomation_pm_bri_end')) }}
Here’s a really bad example of what I’m trying to do…
'TEMPLATE NAME = LIGHT_PERCENTAGE'
IF
{{ now() >= today_at(states('input_datetime.lightautomation_am_bri_start')) or
now() <= today_at(states('input_datetime.lightautomation_am_bri_end')) }}
= "TRUE"
THEN
{{ states('input_number.lights_brightness_am') }}%
ELSE
{{ states('input_number.lights_brightness_pm') }}%
ELSE IF
100%
END
}}
I guess your are more looking for one sensor that holds the brightness percentage to be used when turning the light on, and this varies depending on the time of the day, right?
If so it should be possible to define a template sensor that does the trick.
Something like this:
and is used if the period is with in the same date, while or is used for periods that crosses a date.
I this case we know that the am period crosses a date (starting in the evening of one day and ending in the morning of next day) and that is why or is used, while and is used between the start and end conditions of the am period.
Tried to replicate your setup. I am a bit confused:
input_datetime.lightautomation_am_bri_start = 22:00 is that 10 PM? input_datetime.lightautomation_pm_bri_start = 7:30 is that 7:30 AM?
so am period starts at 10 PM and pm period starts at 7:30 AM, then the helper naming is probably confusing.
Anyway, if you are not intending to have a gap between the am and pm brightness periods, then I’d rather suggest that you only have the start of each period. The end is defined by the start of the other period
My intention was to have two periods where I could customise the light percentage.
Between these times, the percentage would be low (currently 20%) input_datetime.lightautomation_am_bri_start = 22:00 (10pm) input_datetime.lightautomation_am_bri_end = 07:29 (7:29am)
Between these times, the percentage would be medium (currently 55%) input_datetime.lightautomation_pm_bri_start = 07:29 (7:29am) input_datetime.lightautomation_pm_bri_end = 22:00 (10pm)
These are currently covering the 24hours, however, on my automations, if these times fail then it defaults to 100%… So I suppose the naming is very confusing (sorry )
I added AM & PM ‘Brightness / times’ as I personally found two times that I wanted to control, everything else can be 100%.
Sorry I keep writing, but the following version of the template is more correct.
The other one is not precise and can give wrong results in some cases;: