Vacation lights, ie replay from history

Hi,
So there has been many things written about replay from history sensor, however all of those are touching on using “ON” state, and nothing more. There is a lot of kung-fu with node red etc … But can somebody please explain how to for example use history sensor with basic automation script firing every minute (or other interval), to set light to given state, brightness and colour ?

A ready script would be nice, but I think we all would like to learn more about history_stats and how to use it for other things and documentation is not very helpful here.

What is a “history sensor”?

You could use an SQL sensor to get the state of an entity x days ago (where x is less than your purge_keep_days, which is 10 days by default). You would need one of these sensors for every entity you want to control. Then the automation would look like this:

trigger:
  - platform: state
    entity_id: 
      - sensor.my_light_3_days_ago
      - sensor.my_switch_3_days_ago
      - etc...
    not_to:
      - unknown
      - unavailable
action:
  - service: "light.turn_{{ states('sensor.my_light_3_days_ago') }}"
    target:
      entity_id: light.my_light
  - service: "switch.turn_{{ states('sensor.my_switch_3_days_ago') }}"
    target:
      entity_id: switch.my_switch
  - service: etc...

This is the closest thing I know of using HA configuration to accomplish it. I used it as a basis for what I’m currently using:

or there’s an integration that I tried. I like the one I’m using better but it looks like it works OK too:

you can install it via HACS.

1 Like

yeah, I meant “history stats”. Sorry it was around 2 am.
Anyway. How to get a colour and brightness out of your SQL sensor ?

I don’t know how to get the attribute value x time ago with SQL. I’m sure it can be done, I’m just not sure how.

Might be worthwhile starting a new topic with a more relevant title like “How do I use an SQL sensor to retrieve a past attribute value?”.

That should have more of a chance of attracting the SQL experts.

:saluting_face:
roger.

as @tom_l suggested, let’s use a real world entity

light.parents_bathroom_main_light