Activating a schedule via automation?

Right. I’m stuck, and I’ve searched but I’m not even sure what I’m searching for!

I have the following (simplified) setup:

  • I have a hotel, with nine rooms. I’ve linked into the API of my booking system which can tell me whether a room is booked or available today, and have an entity for each room returning “Booked” or “Available”.
  • Each room has a heater in it connected to a Shelly, which presents an entity to homeassistant.

I want to the heating to come on from, say, 7-10 in the morning, then again from 6-10 in the evening, but only if the room is booked. Easy enough, done and sorted using a scheduling helper to trigger and the booked status as a condition using two automations - one to turn the heating on, one to turn it off according to the schedule.

But if the room becomes booked, then it must turn the heating on, but only if the schedule is active. Also relatively easy, using the booking as a trigger, and the schedule as a condition. Then I can turn it off again if the room becomes unbooked (e.g. due to a cancellation).

So far that’s four separate automations for each room for the heating, and there are nine rooms. Isn’t there an easier way to do this? It feels wrong to use the booking status to trigger an automation based on the schedule, plus if I trigger the automation based on the schedule, it won’t turn on the heater if it’s in the middle of it’s ‘on’ cycle because no event has been generated by the scheduled automation.

Additionally, and here it gets complicated - The room will be marked as available at midnight despite being occupied (because it’s available to be booked that same day). Is there some way I can store last night’s booking value within HA until 11 am (checkout time) so that it can be referenced by the scheduling automation the following morning?

I’ve sort of tied myself in knots and this feels like something which must have been done a million times before - hoping someone out there has done it already.

I’m a beginner but happy to get my hands dirty in YAML if I can just figure out what exactly I’m trying to do.

1 Like

If the names of the heaters in all nine rooms, and booking status indicators, adhere to some sort of common format, it may (special emphasis on the word “may”) be very easy to consolidate the four automations into one and make it support all nine rooms. Post the automations.

As for the “here it gets complicated” part, let’s cross that bridge after sorting out the consolidation.

Thanks Taras. I set up the automations using the GUI to generate example YAML so they’re a bit messy, but I’m finding increasingly I’m more comfortable editing the YAML where everything is in one place so happy with that. I’ve not tidied things up massively because if there’s a better way to do this then it seems wasteful. And thanks for your patience with a newbie…

Here are the automations I have in place:

- id: '1670929889071'
  alias: Room 2 heating
  description: Turn room 2 heater on if booked
  trigger:
  - platform: state
    entity_id:
    - sensor.budget_twins_booked
    from: Available
    to: Booked
  condition: []
  action:
  - type: turn_on
    device_id: c84347ed9e272eeaf1e3e3c1949e5ee7
    entity_id: switch.shellyplus1pm_a8032ab953e4
    domain: switch
  mode: single
- id: '1670947445763'
  alias: Booking trigger room 2 heater off
  description: Turns off room 2 heater when room becomes available
  trigger:
  - platform: state
    entity_id:
    - sensor.budget_twins_booked
    from: Booked
    to: Available
  condition: []
  action:
  - type: turn_off
    device_id: c84347ed9e272eeaf1e3e3c1949e5ee7
    entity_id: switch.shellyplus1pm_a8032ab953e4
    domain: switch
  mode: single
- id: '1671481359125'
  alias: Room 2 heater schedule trigger
  description: Turns on room 2 heater dependent on schedule
  trigger:
  - platform: state
    entity_id:
    - schedule.underfloor_heating
    from: 'off'
    to: 'on'
  condition:
  - condition: state
    entity_id: sensor.budget_twins_booked
    state: Booked
  action:
  - type: turn_on
    device_id: c84347ed9e272eeaf1e3e3c1949e5ee7
    entity_id: switch.shellyplus1pm_a8032ab953e4
    domain: switch
  mode: single