alias: Room sensor ON
description: ""
trigger:
- type: occupied
platform: device
device_id: xxxx_mmwave
entity_id: xxxx_occupancy
domain: binary_sensor
condition: []
action:
- type: turn_on
device_id: xxxx_switch
entity_id: xxxx_light
domain: light
- device_id: xxxx_mmwave
domain: number
entity_id: xxxx_sensitivity
type: set_value
value: 6
mode: single
alias: Room sensor OFF
description: ""
trigger:
- type: not_occupied
platform: device
device_id: xxxx_mmwave
entity_id: xxxx_occupancy
domain: binary_sensor
condition: []
action:
- type: turn_off
device_id: xxxx_switch
entity_id: xxxx_light
domain: light
- device_id: xxxx_mmwave
domain: number
entity_id: xxxx_sensitivity
type: set_value
value: 1
mode: single
- I have 2 automations for a mmwave sensor to on/off the lights.
- I set the mmWave sensitivity at 1 normally to detect if someone entered the room
- Once
occupied
, I increase the sensitivity to 6, to prevent it from turning off due to false alarm
- The reason I don’t let it stay at 6 is because it is too sensitive
- However, when sensitivity is changed, the mmwave becomes
not_occupied
for a split second, which triggers the OFF, and then becomes occupied
again, thus making the lights go on → off → on → off
- Is there a way to overcome this?
Use the for:
option in your trigger.
alias: Room sensor ON
description: ""
trigger:
- type: occupied
platform: device
device_id: xxxx_mmwave
entity_id: xxxx_occupancy
domain: binary_sensor
for: "00:00:01"
condition: []
action:
- type: turn_on
device_id: xxxx_switch
entity_id: xxxx_light
domain: light
- device_id: xxxx_mmwave
domain: number
entity_id: xxxx_sensitivity
type: set_value
value: 6
mode: single
It will create a slight delay but should hopefully filter out the pulse.
2 Likes
I think it has to be in OFF instead of ON, let me see how many seconds it should be
Thanks, it had to be 3 seconds at the OFF side.
Still open to other options if any ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=10)
Didn’t you want to stop it from thinking there was no occupancy when the sensor dipped to ‘not occupied’? In this case you need it as per what I had.
The timing I set to 1 second because you mentioned a millisecond dip to ‘not occupied’, so 1 second should cover that.
Hmm, so right after the first occupied
, HA sets it to high sensitivity (HS). But this HS causes the device to erroneously report not_occupied
(A) for a brief period before going back to occupied
(B).
If uncorrected, the lights will go off while human is present due to A, which sets the device back to low sensitivity. And because of B, HA attempts to set it to HS once again.
I think you were trying to overcome B, whereas A was the root of the problem.
Ah, yeah ok. Sorry, I’m with you now.
Great, yours is an elegant solution, but I had higher expectations from a mmWave sensor, so the 3 seconds is kind of a bummer.
So I take i the sensor doesn’t have separate settings for initial detection vs holding detection?
eg:
![image](https://community-assets.home-assistant.io/original/4X/a/e/6/ae6d56956796bd59803cd7c05ece12353e38f877.png)
To answer your question, no. It’s a Tuya ZY-M100. What is your device? Honestly, I think my device’s behavior is a bug, just not sure where to report it.
That screenshot was from this, running ESPhome.
I’m guessing you are using ZHA which according to this article doesn’t yet have full compatibilty with that sensor. I’d take a look at the ZHA Github page to see what is happening with the development for that sensor. Often it’s not too far away.
EDIT: that’s the same set of features you have, so I guess it’s just a bit limited.
Actually, I’m very happy with its detection performance, both on and off. The only issue is this wrong reporting.
I filed a bug report in the Smart Life app. Fingers crossed.
@sparkydave
In my OFF script, is there a way to check for a global flag? I’m thinking of setting a skip
flag in my ON script when changing sensitivity, this way, OFF will know it should skip this report.
Sure, include a condition in your automations to check for the state of the particular ‘flag’ you are talking about.
Did not work.
I used an input toggle as a flag, set it in the ON script, adjust sensitivity, delay 3 seconds, and clear the flag.
But in the OFF script, the flag is always cleared. Seems the automations are not asynchronous.
Can you post what you have?
alias: presence in room (Advanced)
description: ""
trigger:
- type: occupied
platform: device
device_id: xxxx_mmwave
entity_id: xxxx_occupancy
domain: binary_sensor
condition: []
action:
- type: turn_on
device_id: xxxx_switch
entity_id: xxxx_light
domain: light
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.skip_room_absence
- device_id: xxxx_mmwave
domain: number
entity_id: xxxx_sensitivity
type: set_value
value: 4
- delay:
seconds: 5
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.skip_room_absence
mode: single
alias: absence in room (Advanced)
description: ""
trigger:
- type: not_occupied
platform: device
device_id: xxxx_mmwave
entity_id: xxxx_occupancy
domain: binary_sensor
condition: []
action:
- if:
- condition: state
entity_id: input_boolean.skip_room_absence
state: "off"
then:
- type: turn_off
device_id: xxxx_switch
entity_id: xxxx_light
domain: light
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.skip_room_absence
- device_id: xxxx_mmwave
domain: number
entity_id: xxxx_sensitivity
type: set_value
value: 1
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.skip_room_absence
mode: single
I’m kinda confused with what you are trying to achieve there.
If the input_boolean is OFF, you turn OFF a light, then turn ON the boolean, change the sensor sensitivity, then try to turn the boolean ON once again…
Perhaps use the choose:
function instead and split your automation action to the two scenarios you want to have happen.
Can you explain in dot points what options you want to have happen in each situation?
It is easier to use the words presence
and absence
to avoid confusion with the state of the light.
-
If I’m present, lights ON
-
If I’m absent, lights OFF
-
And I want it real snappy because it is an mmWave sensor
-
But this simple requirement is greatly complicated by the erroneous reporting, referred to as A.
-
From tests, I know A will happen within 2 seconds of adjusting the sensitivity
-
skip_room_absence
is my way to workaround A, i.e. when I adjust the sensitivity, I know an A is coming and I want to tell the absence
automation to skip
it just once
-
To explain the code, in the presence
automation, I set skip_room_absence
to on
, then adjust the sensitivity, wait (5 seconds) for A to come and go, then set skip_room_absence
back to off
-
During the 5 seconds of waiting, I expected the absence
automation to receive A, and skip
it because skip_room_absence
is on
, however this is where my expectations fall short, for some reason, skip_room_absence
is always off
-
I also want my skip_room_absence
to be in a known state, so both automations will turn it back to its normal value of off
, it is just a way to deal with whatever comes my way because using timing to control state is just a bad idea, but I see no better alternatives unless Smart Life fixes this