Automation: Turn on heating at 16:00:00 if somebody was home within last 12 hours

Hi all,

I am using hass to (among others) automate my heating at home. I want it to turn on at 16:00:00 (so before I get home) to have it nice an cosy when I arrive at home. However, this is only valid on days where I have been home earlier (i.e. I am not on vacation).

I there a way to look back in time (e.g. using the “history” functionality) to check, whether my group of devices has been home within the last 12 hours? If so, what is the easiest way to do so?

I did look through the documentation but could not find anything on that topic.

Thank you very much

Bastian

Create an input boolean to track the “holiday” state. Then you have one automation to turn it off when anybody comes home, and other that turns it on if the group has been not_home for 12 hours. Use that being off as a condition in your heating automation.

You could also use the Google travel time component, look at how far away you are. You could even link it in with turning on the heating when you’re heading towards home, and within a certain amount of time from home.

Thank you very much for the prompt reply - I will give it a try and post the configuration here, once I am satisfied!

Hi!

This approach indeed works.

# Is anybody home today?
input_boolean:
  bool_homeday:
    name: Home Day
    initial: off

automation 20:
  alias: Set Homeday
  trigger:
    platform: state
    entity_id: group.myself
    from: 'not_home'
    to: 'home'
  action:
    - service: input_boolean.turn_on
      data: 
        entity_id: input_boolean.bool_homeday

automation 21:
  alias: Unset Homeday
  trigger:
    platform: state
    entity_id: group.myself
    from: 'home'
    to: 'not_home'
    for:
      hours: 12
      minutes: 0
      seconds: 0
  action:
    - service: input_boolean.turn_off
      data: 
        entity_id: input_boolean.bool_homeday

If you have this, you can let any automation depend on it. For example:

automation 3:
  alias: Enable Heating
  trigger:
    - platform: time
      at: '05:00:00'
    - platform: time
      at: '16:00:00'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'binary_sensor.workday_sensor'
        state: 'on'  
      - condition: numeric_state
        entity_id: 'sensor.dark_sky_temperature'
        below: 12.0
      - condition: state
        entity_id: input_boolean.bool_homeday
        state: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.fussbodenheizung