I recently made some motion sensors using ESP8266 modules and PIR sensors that publish their state to MQTT. When motion is detected, I can see it in HA, so I know that they are reporting properly, and HA is working fine with the broker. When I try to set up an automation to have lights turn on based on motion detection however, the lights do not turn on. I have other automations that do work, such as patio lights turning on at sunset and off at midnight, and lights dimming when media is played on my chromecast, so I am really not sure what I am doing wrong.
Are you sure that your entity_id is binary_sensor.Hallway2Motion ? From the name of the sensor I guess it will be slightly different. Check it at the dev tools page. ( < > ).
To check if it has triggered, take a look at the logbook.
For your scene…have you checked (again ) it’s the right name ?
Also, you can put here your whole automation to check if there’s any error.
I have a simple motion detection automation working, perhaps this will help. I had to use lowercase ‘on’ instead of ‘ON’, but I’m not sure if that is what got it working. I also added “-” in front of platform.
automation:
alias: Motion turn on lamp
trigger:
- platform: state
entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
state: 'on' # from: 'off' also works here for me.
action:
service: light.turn_on
entity_id: light.lamp
Ok, so as it turns out, you guys were right about the capitalization. States are lower case, and have nothing to do with the MQTT payloads. Thanks for all your help!
As @sebastianapw mentioned can you please give us your sketch as I have a PIR motion sensor and I am not sure where to connect it i.e. on ESP8266 or Raspberry pi? As my lights switch on via MQTT.
Question is how can I integrate my lights with my PIR sensor ? Do you have a similar set up?
Hi, I found a good script on GitHub, link below.
If you have a NodeMCU the numbers for the connection pins are a little confusing, if you need any help there, just reply on this post.
You can wire the PIR as following:
VCC --> 3,3V VCC Pin on ESP8266
GND --> GND on ESP8266
DATA --> PIN 12 on a NodeMCU this equals to D6
On a Raspberry Pi you can use the RaspberryPi GPIO Binary Sensor component, wiring is also easy, for further questions please reply.
Can you please post your automation.yaml file and the binary sensor part in your configuration.yaml file?
On a side note: the automation.yaml file is meant to be saved in the same directory as the configuration.yaml file is that correct?
I have everything set up but when my NodeMCU detects motion (checking from the serial monitor) the lights do not turn on. I have changed the motion topic in the ino file to match my mqtt lights command topic.
I have created a new automation.yaml file and placed it in the same directory as my configuration.yaml file. I have copied the automation code and changed some bits as shown below: