Holiday / Vacation mode

Quick note for others using mirekmal’s original code. This may be obvious to most but as a newbee, it has taken me a short while to spot! As well as setting up the family and light groups you also need to set up the entity_id: input_text.light_to_switch. I used the helpers page in the UI to add a text helper “light_to_switch” I also had to mess with the quotes a bit in the data_template lines to get the Automation menu in the UI to read the automation file after adding the code but once that syntax was sorted it works great! Thanks again

This works great! Thanks for sharing, both of you.

Hello mirekmal,

I’m not sure I’ve done it right.
Should I replace ‘entity_id’ with something else?
I got this error: Entity ID unknown is an invalid entity ID for dictionary value @ data[‘entity_id’]

Thanks a lot

It should look exactly like in the template. entity_id in this case is what is extracted from the group.
I tried to simulate some errors by changing things in template and configuration, but never got one as yours. What do you get if you put just

{{ state_attr('group.simulation_lights','entity_id') | random }}

into template editor?

Hello mirekmal, I got:

TypeError: object of type ‘NoneType’ has no len()

Thanks

To me it indicates that group.simulation_lights might not exists in your config. Did you defined it and it contains at least one light? It can be either light group or regular group (advantage of second case is that then it can contains not just lights, but also switches). Can you verify this? Lets put group.simulation_lights into states. If you do not find it the it is not defined. You need to either define it or perhaps you already defined another group of lights you want to use in simulation - then replace this in template with desired group.

You are right. The group I’ve created was group.simulation_light, I forgot the “s”
Sorry, my mistake
Thank you again!

Hello Gechu;

So I have this automation working flawlessly, thanks so much. I do however have one small thing I would like to change; it involves the “Notice” "{{ switch }} will be turned on for {{ duration }}". Currently it shows the device name, how can i get this to show a familiar name for the device - one that is more recognizable?

Hi there!

{{ light }} is a string variable that holds an “entity_id” of a lamp. Quickly googling, I think you should be able to use this code to get the name of a lamp: entity_id.split(’.’)[1]

But you have to use string concatenation to replace “entity_id” with “light”. - not sure how to format that code. Give it a try yourself, and ping back with your findings, and if you’re still having problems, Ill look into it more deeply.

"{{ state_attr(switch, 'friendly_name') }} will be turned on for {{ duration }}"

will give you the friendly name you condigured for the switch.

Hello Burningstone;

That seems to be what I’m looking for, but it doesn’t work all the same. It throws errors on reboot. Perhaps because the switch is selected dynamically within the script?

Finally, I seem to have got it. I added the missing “)”, but that didn’t seem to do it… The problem seems to have been the constant YAML spacing issue. Works now, thanks!

Yeah, totally forgot that bracket, fixed it now. Glad that ypu got ot to work.

Hello,
can someone help me adapt the script of@mirekmal and @gechu with shelly switches? I control the lighting with shelly switches, but I have a problem with it.

I created switches.yaml included these:

  • platform: group
    name: simulation_switches
    entities:
    • switch.mama_allolampa
    • switch.shellyplug_s_083a8dc21ed3

and I included configuration.yaml:
switch: !include switches.yaml

and I created switches_duration script:
‘1692192914417’:
alias: switches_duration
mode: parallel
description: Lámpák bekapcsolása és utána kikapcsolása
fields:
switch:
description: Mama állólámpa kapcsolása
example: switch.mama_allolampa
duration:
description: Világítás idejének beállítása percben
example: ‘25’
sequence:

  • service: homeassistant.turn_on
    data:
    entity_id: ‘{{ switch }}’
  • delay: ‘{{ duration }}’
    max: 10

finally I created Vacation Ligths automation:

  • id: ‘1692097460528’
    alias: Vacation Lights
    description: Távolléti világítás
    trigger:
    • platform: time
      at: ‘14:53:00’
      condition: []
      action:
  • service: script.switches_duration # Pass randomly selected light from “group.simulation_switches” as script variable “switch”
    data:
    switch: “{{states.switch.simulation_switches.attributes.entity_id | random}}” # random value between 5 & 30
    duration: “00:{{ ‘{:02}’.format(range(5,30) | random | int) }}:00”

Unfortunately it doesn’t work and I get errors.

Thanks for your help.