Group devices/entities but only during a time range

Is there a way to only have some groups defined during a particular time range? Or perhaps only follow a YAML config “!include” during certain time ranges?

I’ve set up a bunch of groups in the groups.yaml file. I’ve been using many of them to put together devices/entities for the various outlets and plugs and lights for the holidays. I only really care about these particular groups during the winter holiday period. Once that is done, I will re-use many of the same entities for other tasks.

I know I could enable/disable related automations. I was thinking that enabling/disabling groups could be another way to accomplish what I want. As I’m thinking about it, I also realize its possible that leaving automations enabled but calling on groups that were disabled could result in undesirable errors / log messages.

Thanks!

I’m not sure this answers your exact question, so I may be a bit off-base. Here’s what I do for the holidays:

  1. Add an all-day Google calendar item that says “Christmas.” It starts when we want to light up the holiday lights and ends when we no longer have the lights up. This definition goes in my google_calendar.yaml file that is in the root configuration directory (here’s the HA reference to setting this up if you don’t already have it: Google Calendar Event - Home Assistant (home-assistant.io)):
- cal_id: [email protected]
  entities:
  - device_id: turn_on_christmas_lights_family
    ignore_availability: true
    name: Christmas Lights
    track: true
    search: "#Christmas Lights"
  1. Created a binary_sensor.christmas_lights in my binary_sensor.yaml file with the following template. When the calendar item is on, so is the binary_sensor:
- platform: template
  sensors:
    christmas_lights:
      friendly_name: "Christmas Lights Available"
      value_template: "{{ is_state('calendar.turn_on_christmas_lights_family','on')}}"
  1. Use binary_sensor.christmas_lights as a condition to do things. I have a card on my dashboard that tells me when the binary_sensor is true:
  - cards:
      - type: 'custom:button-card'
        template: binary_sensor_name_label_stateformat_truewhenon_noicon
        entity: binary_sensor.christmas_lights
        name: >
              [[[  return "Christmas Lights"; ]]]
        icon: 'mdi:pine-tree'
    type: horizontal-stack
  1. I also use it in automation templates to select the right scene:
  - service: scene.turn_on
    data_template:
      entity_id: >
        {% set state    = states('media_player.roku_3_family_room') %}
        {% set duration = state_attr('media_player.roku_3_family_room','media_duration')|int %}
        {% if   state == "playing" and is_state('binary_sensor.christmas_lights','off') and duration > 60 %} scene.living_room_movies_2
        {% elif state == "playing" and is_state('binary_sensor.christmas_lights','on')  and duration > 60 %} scene.living_room_movies_christmas_2
        {% elif state == "paused"  %}                                                                        scene.living_room_medium_2
        {% else %}                                                                                           scene.living_room_bright_2
        {% endif %}
      transition: 5

The only difference between the two scenes are the Christmas lights in the room (they aren’t there in the non-Christmas scene).

Hope this gives you some ideas!

1 Like