Help me with Hue outdoor motion sensor + lights

Hi,

It’s my second day using HA and I’m trying to setup an automation which I’m not quite sure if I got the concept right.
Tried to search for examples and asked ChatGPT but would appreciate if someone could review the code and tell me if it does the following scenario I’m trying to configure:

  • Before sunset = motion detection off, lights off
  • After sunset = turn on motion detection, lights on 50%
  • If motion detected (during night): turn on lights 100% for 5min, then go back to 50% brightness.
  • At sunrise = turn off motion detection, lights off.

So far, I got this code, does it seem correct? I am getting many different type of results with ChatGPT so not sure if I can trust it :slight_smile:

alias: Carport sensor automation
description: ""
trigger:
  - platform: state
    entity_id: update.carport_sensor
    to: "on"
  - platform: sun
    event: sunset
  - platform: sun
    event: sunrise
condition:
  - condition: or
    conditions:
      - condition: sun
        before: sunset
        after: sunrise
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: sun.sun
            state: below_horizon
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 50
              kelvin: 2000
            target:
              device_id: 8d914bef0c3392074127e279eeb33bd7
      - conditions:
          - condition: state
            entity_id: update.carport_sensor
            state: "on"
          - condition: state
            entity_id: sun.sun
            state: below_horizon
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 100
              kelvin: 6500
            target:
              device_id: 8d914bef0c3392074127e279eeb33bd7
          - delay:
              hours: 0
              minutes: 5
              seconds: 0
              milliseconds: 0
          - service: light.turn_on
            target:
              device_id:
                - 8d914bef0c3392074127e279eeb33bd7
            data:
              kelvin: 2000
              brightness_pct: 40
      - conditions:
          - condition: state
            entity_id: sun.sun
            state: above_horizon
        sequence:
          - service: homeassistant.turn_off
            data: {}
            target:
              entity_id: update.carport_sensor
              device_id:
                - 2007a232996a31b01729422c2233e253
                - 66deb9be8b6447188f2637e1b8868c89
                - 0b60a473957c6f98da10c51f28af1010

Thanks!

Don’t do that. If you don’t know what you are doing it will only make things worse as you can’t yet tell what is garbage and what is not.

That is not a motion sensor. It is a firmware update available sensor.

You probably want something like binary_sensor.carport_sensor. Check it. It also needs to be replaced with the correct entity in your actions in a few places.

Remove this, it is not correct or required and will actually prevent some of your actions from working.

condition:
  - condition: or
    conditions:
      - condition: sun
        before: sunset
        after: sunrise

The rest of your logic is pretty much a GPT hallucination.

Try checking the official documentation instead:

(this also applies to automation actions):

Thanks Tom, looking at some examples it surely looks like ChatGPT just outputs some crap code which makes no sense.
However, looking at available options for the hue outdoor motion sensor, I don’t have that many entities to choose from.

Will there be a difference in the number of entities received when using the Philips Hue Bridge with Home Assistant compared to using Zigbee2MQTT + Mosquitto + HA (I am using the latter)?

For example, If I check my number of entities to use I only see these:

You mentioned binary_sensor.carport_sensor, could this be the one in my case maybe: binary_sensor.carport_sensor_occupancy. The other ones doesn’t seem relevant for turning on/off motion sensor.

Yes it is that one.