Presence simulator (random turn on/off lights during the night)

Hi there,

I want to share my “presence simulator” in case someone needs it.
It does what its name tells:
Case 1: turns on/off lights when I am not at home and the my Risco security system is activated
Case 2: turns on/off light during the night when I am at home and the security system is activated for the garden only

I created one config for each case. If case 1 is activated case 2 does not start. In case 2 is activated case 1 does not run.

Here I’m gonna share just case 2 config since I have completely tested it. Case 1 is not enough tested because covid lockdown…

Anyway, case 2 works fine so maybe case1 may work as well.

This is the automation.yaml component:


# simulatore luci con allarme parziale (non incluso in simulatore)
- alias: Simulatore presenza - looper luci allarme parziale
  trigger:
    - platform: state
      entity_id: alarm_control_panel.risco_security
      to: 'armed_home'
      for:
        seconds: 60
    - platform: state
      entity_id: sun.sun
      from: 'above_horizon'
      to: 'below_horizon'
    - platform: state
      entity_id: media_player.tv_soggiorno_2								# the looper does not start if I'm watching TV in the living room
      to: 'off'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.presence_simulator
        state: 'off'
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'
      - condition: not
        conditions:
          - condition: state
            entity_id: media_player.tv_soggiorno_2							# the looper does not start if I'm watching TV in the living room
            state: 'on'
  action:
    repeat:
      while:
        - condition: and
          conditions:
            - condition: state
              entity_id: alarm_control_panel.risco_security
              state: 'armed_home'
            - condition: state
              entity_id: sun.sun
              state: 'below_horizon'
            - condition: not
              conditions:
                - condition: state
                  entity_id: media_player.tv_soggiorno_2						# the looper stops if living room TV is on
                  state: 'on'
      sequence:
        - delay: "00:00:02"
        - service: script.turn_on
          data_template:
            entity_id: "script.simulatore_luce_{{ range(2,5) | random}}" 				# randomply turn on lights in some rooms (not bed rooms!)
        #- wait_template: "{{ is_state('input_boolean.presence_simulator_wait_light', 'off') }}"	
        - delay: "00:00:02"
        - wait_for_trigger:
            - platform: state
              entity_id: input_boolean.presence_simulator_wait_light
              from: 'on'
              to: 'off'
              for: 5
        - delay: "00:{{ '{:02}'.format(range(1,31) | random | int) }}:00"

This is the script.yaml component:


simulatore_luce_1:
  alias: Simulatore - luce 1 - lampadario bedroom				# this light is not turned on in case 2 but just in case 1
  sequence:
    - service: input_boolean.turn_on
      entity_id: input_boolean.presence_simulator_wait_light
    - service: light.turn_on
      entity_id: light.bedroom
    - delay: "00:{{ '{:02}'.format(range(5,29) | random | int) }}:00"
    - service: light.turn_off
      entity_id: light.bedroom
    - service: input_boolean.turn_off
      entity_id: input_boolean.presence_simulator_wait_light

simulatore_luce_2:
  alias: Simulatore - luce 2 - lampadario tavolo cucina
  sequence:
    - service: input_boolean.turn_on
      entity_id: input_boolean.presence_simulator_wait_light
    - service_template: >                                                         # if someone is in the kitchen the scripts does not turn off the lamp (my wife doesn't like lighting during the night...)
        {% if states.light.mobile_bianco_led_inferiore.state == 'off' %}
          switch.turn_on
        {% elif states.light.mobile_bianco_led_inferiore.state == 'on' %}
          switch.turn_on
        {% endif %}
      entity_id: switch.lampadario_cucina
  #- service: switch.turn_on
  #    entity_id: switch.lampadario_cucina
    - delay: "00:{{ '{:02}'.format(range(5,29) | random | int) }}:00"
    - service: switch.turn_off
      entity_id: switch.lampadario_cucina
    - service: input_boolean.turn_off
      entity_id: input_boolean.presence_simulator_wait_light

simulatore_luce_3:
  alias: Simulatore - luce 3 - lampadario soggiorno piccolo (luce bassa)			# this light has a step dimmer with 3 on/off the light is lower
  sequence:
    - service: input_boolean.turn_on
      entity_id: input_boolean.presence_simulator_wait_light
    - service: switch.turn_on
      entity_id: switch.lampadario_piccolo
    - delay: "00:00:01"
    - service: switch.turn_off
      entity_id: switch.lampadario_piccolo
    - delay: "00:00:01"
    - service: switch.turn_on
      entity_id: switch.lampadario_piccolo
    - delay: "00:00:01"
    - service: switch.turn_off
      entity_id: switch.lampadario_piccolo
    - delay: "00:00:01"
    - service: switch.turn_on
      entity_id: switch.lampadario_piccolo
    - delay: "00:00:01"
    - delay: "00:{{ '{:02}'.format(range(5,29) | random | int) }}:00"
    - service: switch.turn_off
      entity_id: switch.lampadario_piccolo
    - service: input_boolean.turn_off
      entity_id: input_boolean.presence_simulator_wait_light

simulatore_luce_4:
  alias: Simulatore - luce 4 - applique sinistro divano
  sequence:
    - service: input_boolean.turn_on
      entity_id: input_boolean.presence_simulator_wait_light
    - service: switch.turn_on
      entity_id: switch.applique_sinistra_divano
    - delay: "00:{{ '{:02}'.format(range(5,29) | random | int) }}:00"
    - service: switch.turn_off
      entity_id: switch.applique_sinistra_divano
    - service: input_boolean.turn_off
      entity_id: input_boolean.presence_simulator_wait_light

simulatore_luce_5:
  alias: Simulatore - luce 5 - applique destro divano
  sequence:
    - service: input_boolean.turn_on
      entity_id: input_boolean.presence_simulator_wait_light
    - service: switch.turn_on
      entity_id: switch.applique_destra_divano
    - delay: "00:{{ '{:02}'.format(range(5,29) | random | int) }}:00" #random delay
    - service: switch.turn_off
      entity_id: switch.applique_destra_divano
    - service: input_boolean.turn_off
      entity_id: input_boolean.presence_simulator_wait_light

input_booleans.yaml component:

presence_simulator_wait_light:

Of course you need to set up components like Risco security system. In case you use another alarm system you need something else…
Any suggestion is appreciated

Hope it helps!
Gekomax :call_me_hand:

3 Likes