Schedule: Switch turning on&off

I want to turn on a switch based on a schedule and then off.

I was told the best way to do is via schedule helper. So I created the helper and set a schedule. And then created an automation when the helper’s state is active, then that calls service to turn on the switch.

And when the helper goes to idle, the switch is turned off.

This automation seemes not to work… maybe I’m missing something. And if it did work then there is a slight flaw to it.

(For example: I want to turn on the switch on Monday at 7am till 9am. So when the status changes of the helper from idle to active. I turn on the switch. But if for some reason the the helper does not change the state then the switch won’t turn on at 7am. But I want to turn on the switch anyway between 7 till 9. But this automation only works at the specific time of 7am)

Any ideas? Thanks!

Could we see the automation? My schedule helpers go on and off rather than active and idle.

alias: “Room_Switch: Dehumidifier On”
description: >-
Turns on Dehumidifier
Dehumidifier helper
trigger:

  • platform: state
    entity_id:
    • schedule.dehumidifier
      from: “off”
      to: “on”
      condition:
  • condition: state
    entity_id: input_boolean.room_dehumidifier_button
    state: “on”
    action:
  • service: switch.turn_on
    data: {}
    target:
    entity_id: switch.room_dehumidifier
    mode: single

I have helper button as a condition to control whether I want the schedule to run or not on a particular day. And it’d always on. So I dont know what else could be causing the automation to not run.
(And please ignore any errors in the structure as when i pasted the yaml from the automation, the structure seems to have messed up)

So this is the case.
You want to turn on dehumidifier and than turn it off. When you want to do it? At specific time or when humidity level reach some point?
I’m not sure that using this helper is the best way to do this automation.
Maybe the easiest way to do it is to create two triggers ids based on humidity level and select choose action to turn humidifier on off when humidity level is above or below threshold.

You need to paste as preformatted text (</> in the toolbar). :grinning:

I think what you have should work - provided the indentation is correct:

alias: Test
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.test
    from: "off"
    to: "on"
condition:
  - condition: state
    entity_id: input_boolean.test
    state: "on"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.test
mode: single

You would need another automation to turn the switch off again.

You might try leaving out the “off” in the trigger. As it stands the automation will not run if schedule.dehumidifier starts out in some other state than “off” - unavailable, for example.

Also, it will only run when the state of the trigger actually changes - at 7am. If you want to have manual control of the dehumidifier as well as a schedule, you could include an input_boolean as a second trigger.

Dehumidifier is just an example in this case.
I want the schedule to work for any device.

But yes I do agree in the case of the Dehumidifier, its best to use the humidity levels to turn it on or off.

I dont see scheduler as key component to most automation. Only device that I have and use scheduler is buderus furnace. It is using its build in scheduler. But even it is using conditions to run.

This automation should work however.
I dont see why the scheduler helper cannot be used for such an automation

Yes I did create an automation to turn it off.

Will the automation still work if I delete the “off” from the trigger. (I assume the automation wants to know the change in state from off to on?) If not, then its a great idea to remove the “off” in the trigger.

Finally, I don’t understand what you mean by change input boolean to control the switch.
I want the switch to turn on between 7am till 9am. But as you said, this automation only runs at 7am. If for any case, the automation fails to run at 7am then it will stay off untill 9am.

But I want to modify this automation in a such a way that even if its past 7am but before 9am, that this automation still runs and turns on the switch.
I don’t know how to do that🙃

Well I use just timer helper for lights. I don’t know will this help but here it is. The problem I want to solve is that I want to turn off lights only when motion is not detected for a minute. Helper is here to start countdown when pir sensor stop detecting motion. But if pir sensor detect motion cancel helper and start counting down again when motion is cleared.

alias: Bathroom mirror light
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.bathroom_motion_sensor_occupancy
    from: "off"
    to: "on"
    id: Motion detected
  - platform: state
    entity_id:
      - binary_sensor.bathroom_motion_sensor_occupancy
    from: "on"
    to: "off"
    id: Motion cleared
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: state
    entity_id:
      - timer.bathroom_mirror_light_helper
    to: idle
    id: Helper
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Motion detected
          - type: is_illuminance
            condition: device
            device_id: 50e83835f19e9a57aefaf434dba281e9
            entity_id: sensor.bathroom_motion_sensor_illuminance_lux
            domain: sensor
            below: 50
            enabled: true
        sequence:
          - service: timer.cancel
            data: {}
            target:
              entity_id: timer.bathroom_mirror_light_helper
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.switch_2
      - conditions:
          - condition: trigger
            id: Motion cleared
        sequence:
          - service: timer.start
            data: {}
            target:
              entity_id: timer.bathroom_mirror_light_helper
      - conditions:
          - condition: trigger
            id: Helper
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.switch_2
mode: single
max_exceeded: silent

I see what you’re doing in the automation.
But im not smart enough to follow the actual code.

Thanks for your help

Well I can’t take a picture of it. Its simple. It uses 3 state triggers. All of them have a trigger id.
For action its using choose. It has 3 options as its has 3 triggers and every choose option is started with trigger id. It might look complicated on the first glance but its basically very simple.