Human occupancy emulation - a noob question

Hi - so I’m setup with Zigbee & RPi and all devices work brilliantly. I’m an experienced programmer but wanted to be lazy and use the visual ‘if this’ methods in automation. Well… didn’t that become a chore! And I think it’s because I only understand the basics of HA automations. I hope someone can enlighten me - so here goes the remit I set myself:

  1. To create a 7 day holiday mode that sufficiently emulates my family living in the house while we’re away - the whole mode to be preferably switched on and off when required.
  2. To measure our human timings for a few weeks and use that to create a schedule. Here is a small example of what I’m trying to do:

Let’s exemplify Sunday (each day has different values to these and each timing has added random seconds) (A = Individual automation created)

Early hours automations for Sunday:
A: 00:30 Turn OFF TV and Amp (turned on from Saturday’s automation at say 21:00)
A: 00:35 Turn on upstairs landing light > delay 15m > turn off landing light
A: 00:36 Turn off living room lamps (turned on from Saturday’s automation at say 19:55)
A: 00:40 Turn on upstairs bathroom light > delay 6m > turn off bathroom light
A: 00:45 Turn on bedroom light > delay 35m > turn off bedroom light
A: 07:30 Open al room blinds

Later hours automations for Sunday:
A: 19:45 Close all room blinds
A: 19:45 Switch on living room lamps
A: 19:47 Switch on TV and Amp, set vol to the usual 50/100
etc etc

The reason I use ON for an item on day 1 evening, and OFF for the same item on day 2 morning, is because I prefer to keep programmed delays short and it gives me scope to alter values simply.

So… the big noob question:

This cannot be the best way surely?! I have a stack of individual automations doing all this. What I suspect is that there is a way to cram these individual automations into a a single one - e.g. a whole week’s worth of automations set up in a script or schedule called ‘Holiday Mode’ or something? One click, and all the grouped ‘human emulation’ automations get switched on, another click they all get switched off. None of the days have the exact same rules because I’m trying to emulate human occupants.

No need to go into huge detail but if experienced HA dudes could tell me what to study further - i.e. my need is to better understand methods I should be using** (and not the ones I’m doing as a beginner) - I would be very grateful! :slight_smile:

Thanks in hope and cheers to all autoheads!
Hub1Cloud0

Create an automation with multiple Time Triggers and assign each one a unique id.

alias: example 333
id: example_333
mode: parallel
trigger:
- id: 'tv_off'
  platform: time
  at: '00:30:00'
- id: 'landing_light'
  platform: time
  at: '00:35:00'
.. etc ..

In the automation’s action use choose to determine which trigger occurred by examining trigger.id.

action:
- choose:
  - conditions: "{{ trigger.id == 'tv_on' }}"
    sequence:
    - service: switch.turn_on
      target:
        entity_id: switch.tv
  - conditions: "{{ trigger.id == 'landing_light' }}"
    sequence:
    - service: light.turn_on
      target:
        entity_id: light.landing
... etc ...
1 Like

I use this, it automates it all, playing back data from you history db. You can choose which entities to use and it’s easy to switch it on and off

3 Likes

To be honest, since you’re a programmer, do yourself a favor and just use something like pyscript to write the automation. The native HA web-built automations quickly become a huge pain to write and maintain as soon as you do something a little more complex than basic if-then logic. It ends up being a lot more work trying to shove a complex logic flow into a mess of yaml mixed with inline jinja than to just write a few lines of clean and easy to maintain Python code.

I’ve converted most of my automations to pyscript myself. There’s also Appdeamon or NodeRed as alternatives.

1 Like

GitHub - slashback100/presence_simulation: Home Assistant Presence Simulation
same here. I flip on virtual switch and the whole thing proceeds to imitate my light changes for the past week. You can set what’s affected (used by the automation) and the time-frame to emulate. I chose a week because that matches different behavior on Saturday and Sunday appropriately for each week it’s running.

1 Like

Wow - great tips from everyone and so quick too! TY so much to all of you above. The stage I’m at is I haven’t replaced all standard switched with smart ones, so its a bit cumbersome at the moment. In this respect, I can’t yet do the presence simulation solution (but oh boy I will be as I get more money to replace the existing infrastructure!)

Special thanks to 123 Taras who has enlightened me lots with that code approach - that is EXACTLY what I was missing from my poor understanding. On top of that I will look into pyscipt from HeyImAlex too.

THANKS ALL :slight_smile: :slight_smile:

1 Like