Simulate Home Presence.

Exported by ChatGPT Exporter at 2023-03-21T19:05:20.202Z

You
can you create me an HomeAssistant action to simulate home presence when I'm not at home?
07:44 PM

Sure, here's an example HomeAssistant automation that simulates home presence using random lights and switch toggles while you're away:

automation:
  - alias: Simulate Home Presence
    trigger:
      - platform: state
        entity_id: device_tracker.your_device_tracker # replace with your device tracker entity id
        to: 'not_home'
      - platform: time
        at: '22:00:00' # replace with your preferred start time for the automation
    action:
      - repeat:
          while:
            - condition: state
              entity_id: device_tracker.your_device_tracker # replace with your device tracker entity id
              state: 'not_home'
          sequence:
            - service: light.turn_on
              data:
                entity_id: group.random_lights # replace with your group of random lights
                brightness: 50
                rgb_color: [255, 255, 255]
            - delay: '{{ range(180, 300) | random }}' # random delay between 3 to 5 minutes
            - service: light.turn_off
              data:
                entity_id: group.random_lights # replace with your group of random lights
            - delay: '{{ range(60, 120) | random }}' # random delay between 1 to 2 minutes
            - service: switch.turn_on
              data:
                entity_id: group.random_switches # replace with your group of random switches
            - delay: '{{ range(180, 300) | random }}' # random delay between 3 to 5 minutes
            - service: switch.turn_off
              data:
                entity_id: group.random_switches # replace with your group of random switches

This automation triggers when your device tracker state changes to "not_home" (indicating that you've left), or at your preferred start time (in this case, 10:00 PM). It then repeats the following sequence of actions as long as your device tracker state remains "not_home":

  1. Turns on a group of random lights for a random duration between 3 to 5 minutes.
  2. Turns off the random lights.
  3. Waits for a random duration between 1 to 2 minutes.
  4. Turns on a group of random switches for a random duration between 3 to 5 minutes.
  5. Turns off the random switches.

This automation uses the range and random Jinja2 filters to generate random delays between the actions. You'll need to replace the device_tracker.your_device_tracker, group.random_lights, and group.random_switches entities with the appropriate entity IDs for your HomeAssistant setup.

07:45 PM
You
what about if I'm not at home for several days? the script is turning on the lights even during the day. Can you propose an update to the script to just turn on light during the night?
07:46 PM

Sure, here's an updated version of the HomeAssistant automation that only simulates home presence by turning on lights during nighttime hours:

automation:
  - alias: Simulate Home Presence
    trigger:
      - platform: state
        entity_id: device_tracker.your_device_tracker # replace with your device tracker entity id
        to: 'not_home'
      - platform: time
        at: '22:00:00' # replace with your preferred start time for the automation
    condition:
      - condition: sun
        after: sunset
        before: sunrise
    action:
      - repeat:
          while:
            - condition: state
              entity_id: device_tracker.your_device_tracker # replace with your device tracker entity id
              state: 'not_home'
            - condition: sun
              after: sunset
              before: sunrise
          sequence:
            - service: light.turn_on
              data:
                entity_id: group.random_lights # replace with your group of random lights
                brightness: 50
                rgb_color: [255, 255, 255]
            - delay: '{{ range(180, 300) | random }}' # random delay between 3 to 5 minutes
            - service: light.turn_off
              data:
                entity_id: group.random_lights # replace with your group of random lights
            - delay: '{{ range(60, 120) | random }}' # random delay between 1 to 2 minutes
            - service: switch.turn_on
              data:
                entity_id: group.random_switches # replace with your group of random switches
            - delay: '{{ range(180, 300) | random }}' # random delay between 3 to 5 minutes
            - service: switch.turn_off
              data:
                entity_id: group.random_switches # replace with your group of random switches

The condition section has been added to the automation, which checks if the current time is after sunset and before sunrise (i.e., during nighttime hours) before executing the actions. This prevents the lights from turning on during the day when you're not at home.

Note that you'll need to replace the device_tracker.your_device_tracker, group.random_lights, and group.random_switches entities with the appropriate entity IDs for your HomeAssistant setup.

07:47 PM
You
this version is good but it is really working if I'm living alone. How can we track the whole family (we are 4 with 2 children without a phone)? is there a different trigger we can use? If it can help I've a connected alarm I used to turn on we nobody is at home.
07:49 PM

If you have a connected alarm system that you use to arm your house when nobody is at home, you can use that as a trigger for your HomeAssistant automation instead of relying on the device trackers of individual family members.

Here's an updated version of the HomeAssistant automation that uses the alarm state as a trigger:

automation:
  - alias: Simulate Home Presence
    trigger:
      - platform: state
        entity_id: alarm_control_panel.your_alarm_entity_id # replace with your alarm entity ID
        to: 'armed_away'
    condition:
      - condition: sun
        after: sunset
        before: sunrise
    action:
      - repeat:
          while:
            - condition: state
              entity_id: alarm_control_panel.your_alarm_entity_id # replace with your alarm entity ID
              state: 'armed_away'
            - condition: sun
              after: sunset
              before: sunrise
          sequence:
            - service: light.turn_on
              data:
                entity_id: group.random_lights # replace with your group of random lights
                brightness: 50
                rgb_color: [255, 255, 255]
            - delay: '{{ range(180, 300) | random }}' # random delay between 3 to 5 minutes
            - service: light.turn_off
              data:
                entity_id: group.random_lights # replace with your group of random lights
            - delay: '{{ range(60, 120) | random }}' # random delay between 1 to 2 minutes
            - service: switch.turn_on
              data:
                entity_id: group.random_switches # replace with your group of random switches
            - delay: '{{ range(180, 300) | random }}' # random delay between 3 to 5 minutes
            - service: switch.turn_off
              data:
                entity_id: group.random_switches # replace with your group of random switches

In this automation, the trigger has been changed to the armed_away state of your alarm system. The condition section remains the same to ensure that the actions are only executed during nighttime hours.

If you have specific lights and switches that you want to use for simulating home presence, make sure to replace group.random_lights and group.random_switches with the appropriate entity IDs for your HomeAssistant setup.

This automation assumes that you arm your alarm system when nobody is at home, and disarms it when someone returns. If this is not the case, you may need to modify the automation to use a different trigger that better fits your specific situation.

07:50 PM
You
which light is it best to use with this script? I'm mean, from which room within the house?
07:51 PM

When simulating home presence, it's best to use a mix of lights from different rooms within the house, rather than just one specific room. This can help create the illusion that people are moving around the house and using different rooms.

Ideally, you should choose lights that are visible from outside the house, such as front-facing windows or balcony lights. If you have smart bulbs or switches installed throughout your home, you can create a group of random lights that includes lights from different rooms.

Here's an example of how you can create a group of random lights:

group:
  random_lights:
    name: Random Lights
    entities:
      - light.living_room
      - light.bedroom_1
      - light.kitchen
      - light.dining_room
      - light.hallway
      - light.bathroom
      - light.outdoor_lights

In this example, the group.random_lights entity includes lights from the living room, bedroom 1, kitchen, dining room, hallway, bathroom, and outdoor lights. You can adjust the list of lights to include other rooms as well.

When the automation runs, it will randomly turn on and off the lights in this group, creating the illusion that someone is moving around the house and using different rooms.

07:52 PM