PIR sensor connected directly to raspberry

Hey guys I bought an AM312 pir sensor that Im planning to use with some lights in the kitchen, if I connect it to gpio pins on the raspberry, how should I set it up to control the lights?
I have the raspberry in the kitchen…

I appreciate any help :slight_smile:

  1. Get the sensor up and running
  1. What kind of lights do you have? How can they be controlled through HA?
1 Like

Thank you… I’m using Milight hub which works via Mqtt.

I was planning to use a nodemcu with the sensor, but I think that it would be easier to connect it straight to the PI.

I’m also using homebridge with HA.

In order for the sensor to be shown in Homebridge, it should have a device_class set, something like this:

`binary_sensor:
  - platform: mqtt
    state_topic: "bruh/sensornode1"
    name: "SN1 PIR"
    payload_on: "motion detected"
    payload_off: "standby"
    value_template: '{{ value_json.motion }}'
    device_class: motion`

How can I make it work with directly with GPIO instead of getting a new nodemcu?

Use customize to set the device class.

I actually tried to set a device class with gpio binary sensor, but the icon won’t change. Any advice?

Im not sure the icon will change based on the device class. That should just be changing the state output. From on/off to two new options based on the device class you chose.

As far as Im aware you can only change the icon with a template sensor.

That may be an option for you. Template the change in name output and the icon.

Would you share a code example please? I already tried to do it but it doesn’t work.

What is the existing name of your binary sensor? What are it’s states?

Binary_sensor.kitchen and it’s state is on or off… thank you very much for your help…!