I made a sketch for a simple PIR sensor using a NodeMCU. It can be used inside HA using either a binary_sensor or sensor using the MQTT platform.
Here is the git repo:
Here is an example of it in use in my home:
This example creates a binary_sensor with an automation to brighten a light_group, if another light sensor is below a threshold and a someone is home, then dimming the lights after 10 minutes if the PIR does not detect movement. This will only occur if the lights are still on.
binary_sensor:
platform: mqtt
name: Kitchen PIR
state_topic: sensor/pir001
payload_on: 1
payload_off: 0
automation:
- alias: Kitchen Motion Detected
trigger:
- platform: state
entity_id: binary_sensor.kitchen_pir
to: 'on'
condition:
- condition: state
entity_id: group.phones
state: home
- condition: numeric_state
entity_id: sensor.sn1_ldr
below: '450'
action:
- alias: Wake Kitchen lights
data:
entity_id: group.kitchen
brightness_pct: 80
service: light.turn_on
- alias: 'Reset kitchen lights 10 minutes after last movement'
trigger:
platform: state
entity_id: binary_sensor.kitchen_pir
to: 'off'
for:
minutes: 10
condition:
- condition: state
entity_id: group.phones
state: home
- condition: numeric_state
entity_id: sensor.sn1_ldr
below: '450'
- condition: state
entity_id: light.kitchen_room_lights
state: 'on'
action:
service: homeassistant.turn_on
entity_id: scene.reset_kitchen_lights
Hardware setup example: