It does seem strange but my use case is that I just started using a CPAP machine. And for the insurance to pay up I have to use it for four hours in a 24 hour period.
And to complicate things my work schedule is a rotating 12 hour shift (4 days on days. 4 days off, 4 days on nights, 4 days off) so I can’t just use a regular time slot because I never really go to bed at a regular time.
So I figured I would setup an automation to turn on an indicator to tell me it’s been at least four hours that I have been wearing the mask. At night I turn on a Sonoff Basic that I have connected to an unused extension cord and I use the green glow of the LED to tell me I haven’t reached the 4 hour mark yet. It’s bright enough to see it on but not so bright it bugs my sleep.
When I work nights and sleep during the day I can’t see the green glow so I use a bedside lamp with a Z Wave bulb in it that I set to a minimum brightness and when it goes off I know I can remove the mask.
So I set up two automations for that triggered by two input booleans. One to turn on the nights indicator & one to turn on the days indicator. And I use a simple delay in the action to wait four hours to turn the indicators and booleans off. So far so good. Until today when I told Alexa to turn on the wrong boolean and my system failed me.
So I figured I could write it all into one automation and use one boolean to control everything. The problem is my services and entity_ids are different depending on which time of day I turn it on.
So I figured I could use the automation and call a script based on the time I turned on the boolean to either run the days script or the night script. easy right. Again, so far so good. But then I thought about the fact that what happens when I turn on either the days indicator when it’s light out and then it gets dark and then light being on will bug me? Or when I turn on the night indicator and it gets light and I can no longer see the green LED glow? So I set up a couple of transitional scripts that takes sunrise/sunset into account to turn off the days//nights indicator and turn on the nights/days indicator.
So I use a wait template to do the transition during the four hour window based oin the sun rising or setting. But then I can’t use another wait template to turn it off at four hours from the time it originally got turned on. So I figured I’d start a timer at the beginning of the script then take the last actions (turn off both the correct indicator and the boolean trigger) when the timer was finished.
So that leads to the question. How do I use the timer.finshed event in a wait_template.
Here is an example of my transitional script:
cpap_morning_transition:
sequence:
- service: switch.turn_on
entity_id: switch.extension_cord_3
- service: timer.start
entity_id: timer.cpap_transition
- wait_template: "{{ is_state('sun.sun','above_horizon') }}"
- service: light.turn_on
entity_id: light.zw_light_2_level
data:
brightness: 15
- service: switch.turn_off
entity_id: switch.extension_cord_3
- wait_template: "{{ what_do_I_put_here_? }}" <---
- service: light.turn_off
entity_id: light.zw_light_2_level
- service: input_boolean.turn_off
entity_id: input_boolean.cpap_indicator