Automation to disable an outlet between certain hours - review/opinions wanted

I need a simple automation that will turn off an illuminated globe in my sons room between certain hours. He often falls asleep with it on and I worry the extra light is causing him to not sleep as well as he could. I want the globe to be turned off from 11pm - 8:30am. I don’t want the globe to turn on at 8:30, only to be possible to turn on. I’m using a smart plug to control the power to the globe and the below automation to control it. I’m posting this thread in hopes someone can let me know if this is a good way to accomplish such an automation or if there are other best practices that may be better.

If this isn’t the type of post that is appropriate here, please let me know and I’ll delete it.

alias: Turn Off Calvin's Globe
description: ""
triggers:
  - trigger: time
    at: "23:30:00"
    id: dark_time
  - trigger: time
    at: "08:30:00"
    id: light_time
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - dark_time
        sequence:
          - type: turn_off
            device_id: 4c1488772581f71a00fee38d3a960d23
            entity_id: 9885b51680a68ae0d93bdbdd2ac7d911
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - light_time
        sequence:
          - type: turn_on
            device_id: 4c1488772581f71a00fee38d3a960d23
            entity_id: 9885b51680a68ae0d93bdbdd2ac7d911
            domain: switch
mode: single
1 Like
alias: Enforce Globe Off Overnight With 1 Minute Allowance
description: >
  Turns off the globe at 23:00 every night.
  If the globe is turned on between 23:00 and 08:30, keeps it on for 1 minute, then turns it off.
trigger:
  - platform: time
    at: "23:00:00"
    id: bedtime
  - platform: state
    entity_id: switch.your_globe_switch_entity_id
    to: "on"
    id: manual_on
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: bedtime
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.your_globe_switch_entity_id
      - conditions:
          - condition: trigger
            id: manual_on
          - condition: time
            after: "23:00:00"
            before: "08:30:00"
        sequence:
          - delay: "00:01:00"
          - service: switch.turn_off
            target:
              entity_id: switch.your_globe_switch_entity_id
mode: restart


This way, the switch will automatically shut off again after 1 min if someone tries to turn it on during the sleep hours.

Unless your son is switching the light back on after 11, then there’s no need for the additional trigger and actions. All you need is the 11 pm trigger and the turn_off action.

Or you could create a schedule helper and use that as the trigger.

That would allow you to have daily variations if you wanted to.

Thanks for sending this, I get it and will read more community guides.

I don’t understand, I must be missing something (likely!).
The globe has it’s own lamp cord switch (little dial switch installed inline in the cord). That’s how he turns it on and off. What I’m trying to accomplish is overriding or killing the supply to the globe. By turning it back on in the morning I’m essentially allowing his globe to be turned on, if he so wishes.

Thanks for sharing the YAML and it’s cool to see your approach.

It wasn’t clear whether you want to prevent him from turning it on at night, or whether you simply want to switch it off automatically for him while he’s asleep.

If it’s the latter, all you need is a time trigger at 11 and the turn off action. For the former, you can use the examples shared above