Making a xiaomi PIR sensors a super sensor

guys, anyone tried this?

can it work? looks simple but if it works, its much better
i do understand the code, but what i dont understand, if motion is detected in deconz already, why/how should it send motion detection again? does deconz actually receive a new signal after 6 seconds?
if so, why is there no option in deconz to configure motion off after 5/6 seconds?

2 Likes

I tried it. My sensor did reset the state to off correctly. But after that the sensor stays off.
In the comments more people had this problem. The video is now offline. Hopefully the maker of this hack will fix this problem. I really found it a cool hack without soldering or modifying the hardware.

well i tried it also
with the rest command, i put the state to “off”, thats nothing special
but in video, he talked that after 6 seconds, he was able to send a motion again
for me it was not 6 , but i needed to wait like 40 seconds, before it triggered motion again

i have conbeen I model

I tried. Besides video and Github is off (don’t know why) I am able to send motion again after 6 seconds

Do you have conbee II version? Or first model

I don’t have conbee, I use zigbee2mqtt. But the information is not for conbee or zigbee2mqtt, the information is for homeassistant. It should work in both zigbee2mqtt and conbee

Yes , buts it’s the hardware that should be able to send the state back, regardless the software…

If I put state to off, I need to dance like 40 seconds before the next motion is triggered to the binary sensor

Maybe it’s conbee related

No, is not the hardware that should be able to send the state back… Is the automation that send a json code to force the entity to go “off state”. Said that, the pir sensor is not consuming more power and continue to work like before. The state change is forced by homeassistant, not by hardware

Hmm , still don’t get it…

Setting the state to “off” that’s indeed rest command, not hardware… It’s just setting a state … No big deal here…
So when state is off… The new “motion detected” is coming from the xiaomi, to deconz to, home assistant setting the binary state to “on” again… So in my opinion that’s the deconz hardware that’s sending the new event… So that’s hardware (conbee) related?

Or am I wrong?

Think you are wrong. I tried to see the zigbee2mqtt logs to identify the sensor activity. When automation from homeassistant is sent to force “off state”, no logs can be seen in zigbe2mqtt.
Besides, the author said that this code worked with conbee and was not hardware related…

Hmm, but the motion should come from somewhere… Normally it can only be triggered by an event from the hardware…

Ok need to check again … I used another command to set the state to off, didn’t use that same rest command. … I use a curl

But if I used my command, the state was also to off…

But I was only be able to send a new motion after 40 seconds , not after 6…
If I could use 6 , then this is a huge improvement!!

I can trigger motion again after 6 seconds. I used rest_command like it was in github code. I was wondering about the state, because after 6 seconds the motion is not “clear” but is “offline” (direct translate). But works like a charm.

ok, can you share that rest command again, video is offline, i created below, allthough dont remember anymore exactlu
i tried below, but get invalid authentication error


rest_command:
  wc_onder_off:
    url: https://localhost:8123/api/states/binary_sensor.xiaomi_sensor_1
    method: POST
    headers: 
      authorization: !secret bearer
      content-type: 'application/json'
    payload: '{"state":"off"}'
    verify_ssl: false




2020-02-19 19:16:56 WARNING (MainThread) [homeassistant.components.http.ban] Login attempt or request with invalid authentication from 127.0.0.1
2020-02-19 19:16:56 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: https://localhost:8123/api/states/binary_sensor.xiaomi_sensor_1. Status code 401.
2020-02-19 19:16:58 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback async_track_state_change.<locals>.state_change_listener(<Event state_...ew_state=None>) at /usr/src/homeassistant/homeassistant/helpers/event.py:81
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 103, in state_change_listener
    event.data.get("new_state"),
  File "/usr/src/homeassistant/homeassistant/core.py", line 364, in async_run_job
    target(*args)
  File "/usr/src/homeassistant/homeassistant/components/automation/state.py", line 92, in state_automation_listener
    call_action()
  File "/usr/src/homeassistant/homeassistant/components/automation/state.py", line 78, in call_action
    context=to_s.context,
AttributeError: 'NoneType' object has no attribute 'context'

There it is:

rest_command_sensor:
    url: http://[IP_ADRESS]:8123/api/states/binary_sensor.movimento
    method: 'POST'
    headers:
      authorization: Bearer [TOKEN]
      content_type: "application/json"
    payload: '{"state": "off"}'

You have authentication problem. First I had the same. You need to write “Bearer” before the code of token

yeah, i noticed , i was already changing :slight_smile:

ok, now it works, it was indeed the word “Bearer”
but need to be home to test it offcourse :slight_smile:

allthough i think my end result stays the same
if i change with a rest command or a curl, state is in both cases off anyway

this is also correct , right? my current automation

- alias: Motion WC Onder On
  initial_state: 'on'
  trigger:
  - entity_id: binary_sensor.xiaomi_sensor_1 
    platform: state
    from: 'off'
    to: 'on'
  action:
  - service: light.turn_on
    entity_id: light.wc
  - delay: '00:00:6'
  - service: rest_command.wc_onder_off

- alias: Motion WC Onder Off
  initial_state: 'on'
  trigger:
  - entity_id: binary_sensor.xiaomi_sensor_1 
    platform: state
    from: 'on'
    to: 'off'
    for:
      seconds: 60   
  action:
  - service: light.turn_off
    entity_id: light.wc

No. You need to have an automation to send off state after X seconds. After that you can do another automation to turn on lights.
See the automation of an example:

- id: '1582110183955'
  alias: Teste
  trigger:
  - platform: state
    entity_id: binary_sensor.movimento
    to: 'on'
  condition: []
  action:
  - delay: '00:00:06'
  - service: rest_command.testesensor

After that I would do 2 automations, one to turn on light after sensor ON, and another to turn off light when sensor OFF for x seconds

yes, thats what i do
in my first automation, when motion is detected , so state from off to on, then i turn on the light, and i turn off the binary sensor to off after 6 sec

my second automation i turn my light off, when motion sensor goes to off, but with a delay of 60 secs offcourse … otherwise my light would go already off after 6 seconds

so in my opinion thats a good automation? it should work like that normally