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?
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…
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'
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
The issue is that when you first start or pair a sensor it does in-fact re-trigger after 5-6 seconds but, then reverts back to 1 min after about 30 minutes… I didn’t test it for long enough.
So, unless there’s a way to re-pair the sensors (every 20-30 minutes) in software, I can’t see a ‘fix’ coming soon.
In my next video, that’ll be up later today, I show how to use a SONOFF Basic to control an ordinary home light fitting, all while keeping the wall switch working as normal.
With your motion sensor and an automation (off an off timer) you’ll be able to use that for your bathroom light and still be able to turn off the light when you leave.