@angadsingh I was trying to implement this same method to door sensors, not motion sensors.
There it is handy to have them as a switch instead of a sensor
Door sensors are only awake for a tiny window. It’s almost impossible to catch them with this method.
Thanks for this solution! For me it works with one Tuya (Woox) motion sensor, but it won’t work when more are added. The pings are not registered in the logbook. Can you see how to fix it? I mean, I can increase the scan_interval but that may miss packages and, in turn, become unreliable.
In configuration.yaml:
input_number:
motion_sensor_idle_secs:
name: "Motion Sensor Idle Seconds"
initial: 600
min: 10
max: 3600
step: 1
icon: 'mdi:motion-sensor'
sensor:
- platform: rflink
automatic_add: true
- platform: time_date
display_options:
- 'date_time'
binary_sensor:
- platform: rflink
devices:
newkaku_0xxxxxx0_1:
name: Bxxxxxxxx_1
newkaku_0xxxxxxb_1:
name: Bxxxxxxxx_2
- platform: ping
host: 192.168.178.76
count: 1
scan_interval: 1
name: ping_tuya_motion_sensor_logeerkamer
- platform: ping
host: 192.168.178.103
count: 1
scan_interval: 1
name: ping_tuya_motion_sensor_slaapkamer
- platform: template
sensors:
tuya_motion_sensor_logeerkamer:
friendly_name: "Bewegingssensor Logeerkamer"
value_template: >-
{{ as_timestamp(states.sensor.date_time.last_changed) - as_timestamp(states.binary_sensor.ping_tuya_motion_sensor_logeerkamer.last_changed) < states('input_number.motion_sensor_idle_secs')|int }}
tuya_motion_sensor_slaapkamer:
friendly_name: "Bewegingssensor Slaapkamer"
value_template: >-
{{ as_timestamp(states.sensor.date_time.last_changed) - as_timestamp(states.binary_sensor.ping_tuya_motion_sensor_slaapkamer.last_changed) < states('input_number.motion_sensor_idle_secs')|int }}
The log shows the following message:
Log Details (WARNING)
Logger: homeassistant.components.binary_sensor
Source: helpers/entity_platform.py:509
Integration: Binary sensor (documentation, issues)
First occurred: 7:25:09 PM (630 occurrences)
Last logged: 8:06:47 PM
Updating ping binary_sensor took longer than the scheduled update interval 0:00:01
I’m running hass.io on a Raspberry Pi 4b (all latest versions).
When searching for a solution I encountered the Nmap Tracker, perhaps that is a clue to what might work. But you guys have way more experience. Any help is appreciated.
Could you possibly point in the right direction to do this for my door sensors? I’ve got tasker now but can’t work out how to use it do this.
Thanks.
I’m using 2 integrations in Tasker, Home Assistant and AutoNotification, plus I’ve got the tuyasmart app installed.
Under Profiles in Tasker I’m using AutoNotification to monitor notifications created by the tuyasmart app that have an exact match of what ever comes through when the door is opened/closed (eg. Front door was opened). Then for the task I have tasker send the command through to HA to change the state of the input_boolean sensor. Essentially you will need 2 Profiles, one for open and one for closed.
I currently don’t know how to auto clear the notifications though, so if you’re using it on something like a wall mounted tablet that you don’t constantly check notifications on (like I am), the top bar becomes quite full.
I’m currently trialling the Ping method suggested above on the door sensors to varying degrees of success.
Update: I’ve removed the Ping method as it was all over the shop with reliability, (but it taught me some stuff so wasn’t a total loss) and gone back to the Tasker method. I’ve worked out how to auto dismiss the notifications. Under the task that sets the input_boolean sensor state, you run another task using AutoNotification -> Cancel. Then for the ID option type %anid This removes the latest notification that has come in.
My Workaround is well cloud dependent, but I will have to see how this develops. I am putting anything Tuya Sensor related (PIR, Door/Reed) into the Tuya app and build the basic automation in the Tuya app. This is then exposed via the existing native app to HomeAssistant as a Scene. This way I dont have full control over the hardware in the native way, but at least got the status information and interface for Automations in HA…
Care to share some specifics / an example? Thanks.
Sure.
I am using Hardware from our local budget outlet called Action here in the Netherlands. Their Brand is called LSC Smart Connect and they sell a limited, but most practical set of devices. All fully compatible with the Tuya App / cloud service and running via 2.4G Wifi.
I am just following the standard setup steps in the Tuya app to register and pair the device with the app. Then I create some basic automation in the Tuya app around this device, i.e. I would use a PIR sensor as a trigger and then set a light to on (which status BTW well transfers into HA via the Tuya integration). So far so good (till here I think evryone called this the “spare plug” trick.
I wasn’t too happy about the need to have a spare plug to bring the status of the sensor into HA (as I just got enough for all devices to be switched) and think this also is a waste of precious hardware which can do much better when used for a real purpose…Anyway, think I am getting ff topic here.
So with the Basic Automation created in the Tuya app and synced with HA, the entity overview in HA revealed to me, that all the automations I had created in the Tuya app were also present as scenes in HA.
So we can use the triggers around that scene in HA to build automations around that like expanding your already existing presence detection automations etc.
Of course it is dependent on the presence of the Tuya cloud service as it routes a lot via that platform, but for the time being, this is a working solution fo me. Speed is acceptable and in case Tuya cloud fails, we still got the physical Switches as backup solution in our home.
I doubt that our internet connection will fail as we got 1 Gbit Fiber with a 4G Backup…
So you’re still needing a dummy switch then?
Not necessarily. I am now using the Tuya automations to receive the motion and door sensor, take the ON action for the respective device (i.e. Motion sensor in the hall switches the hall lights ON), this way I got a ON status synced over from Tuya to HA.
This can be a dummy device or can be a device which is anyway switched by the Motion or Door sensor. Once the Automation is setup in Tuya, it is visible as Scene in HA which I can then use in HA Automations and for instance trigger it in scenes, scripts etc…
The other part of the automation I am usually doing in HA as I can switch off lights in Tuya anyway and (the Motion/Door) Sensors usually do not require bidirectional comms. What would be the added value in sending something into a sensor?!
I meant “dummy switch” as in you are still having to use another Tuya device to replicate/acknowledge the door sensor. Or, have yousomehow created a scene/automation without using a secondary Tuya device?
I must say thank you. I would’ve never thought of this myself (that the device is sleeping and is only alive when detecting something). This method is working perfectly for me with Tuya compatible water leak sensors - only downside for me is not having the battery level visible in HA, but it’s not that big of a deal of course:)
Kudos
Based on the observations by @angadsingh (that the sensor wakes up when motion is detected) and because I have an Asus router with device tracking on, I found that HA’s device tracker also works quite well
# Automations.yaml
# PIR Motion Sensor 1
- alias: 'PIR Motion Sensor 1'
trigger:
platform: state
entity_id: device_tracker.esp_ba03c1
from: 'not_home'
to: 'home'
condition:
condition: time
after: '21:00'
before: '06:00'
action:
service: notify.Telegram
data:
message: 'Motion detected (Sensor 1)'
Hi @Dennis_Vogt. Can you share some more details on what automation can be made? I only have a single tuya sensor, and I cannot see option for any automation besides a notification. The notification shows up as a scene in HA, but I cannot see in the STATES of the Developer Tools how HA acknowledges that a notification was sent. Task as an option does not work either on its own, I think a second tuya device is needed?
tl:dr; This only works when you have an OpenWrt router.
Knowing that the motion sensors connect when they detect motion we can look in the OpenWRT log (logread) for dhcp ack messages, they look something like:
Wed Jun 17 15:13:13 2020 daemon.info dnsmasq-dhcp[1541]: DHCPACK(br-lan) 192.168.1.246 70:91:14:cb:11:db ESP_AA55DD
I’m running the following script on my rpi sshing to my router at 192.168.1.1 with a key
#!/bin/bash
while true; do
logger "Follow the log output filtered on DHCPACK and print timestamps"
ssh -i /home/pi/.ssh/id_rsa -o ServerAliveInterval=60 [email protected] logread -t -e DHCPACK -f | \
while read CMD; do
line=$(echo $CMD | cut -d' ' -f6,12)
stamp=$(echo $line | cut -d' ' -f1)
dev=$(echo $line | cut -d' ' -f2)
#lowercase
dev=${dev,,}
if [[ $dev == *"ESP"* ]]; then
mosquitto_pub -h localhost -t "home/motion/$dev" -m "$stamp"
logger "home/motion/$dev $stamp"
fi
done
done
When a log statement is found with DHCPACK and a tuya device (ESP_XXXX) send a mqtt message on home/motion/esp_xxxx.
In HA I have the general automation:
- id: '159544539864'
alias: Motion dispatch
description: ''
trigger:
- platform: mqtt
topic: home/motion/+
condition: []
action:
- data_template:
entity_id: input_boolean.motion_{{ trigger.topic.split('/')[-1] }}
service: input_boolean.toggle
Then under helpers I just create some boolean inputs that represent the pir sensors I want(it triggers for all tuya devices, so only create pir ones here, but it keeps the rest of the code nice and short)
input_boolean.motion_esp_1812 and I use those to trigger my automations:
- id: '15945789596'
alias: Turn light on for a minute
description: ''
trigger:
- entity_id: input_boolean.motion_esp_1812
platform: state
condition:
- after: sunset
condition: sun
action:
- entity_id: light.hallway_light
service: light.turn_on
- delay: '60'
- entity_id: light.hallway_light
service: light.turn_off
Also using the LSC Smart Connect action devices here.
The presence luci device tracker didn’t work for me reliably (polling interval too big I guess).
This seems to work reliably and instant(no cloud overhead) so far…
Hi,
What’'s your plan about the simpler ping sensor which can just do a simple continuous ping and report back state that way (instead of waking up on intervals and doing pings)?
Because this seems to work for me, but it’s really enoying HA misses the sensor misses sometimes.
It would be nice if the new sensor is coming soon
Excellent work. I’m attempting to use these (inexpensive) PIR sensors to detect animals in my yard at night. I live in a neighborhood that deer seem to frequently visit (at wee hours of the morning). I’m in hopes to turn on that zone’s sprinkler to scare them away.
Ciao Come fate a vedere l’ip in quanto io tramite app smartlife vedo alla voce ip dispositivo il mio ip esterno
I’m trying to use this for some toilet occupancy sensors (thanks Covid) in our bar. the sensors work great and the ping sensor is accurate, however I can only get one of the sensor templates to work reliably ,the other one seems to just flick between on/off constantly. I wonder if I have to define the two sensors differently?
sensor:
- platform: time_date
display_options:
- 'date_time'
input_number:
motion_sensor_idle_secs:
name: Motion Sensor Idle Seconds
initial: 130
min: 10
max: 3600
step: 1
binary_sensor:
- platform: ping
host: 192.168.2.62
count: 1
scan_interval: 1
name: ping_tuya_motion_sensor_gents_toilet
- platform: template
sensors:
ping_tuya_motion_sensor_gents_toilet:
friendly_name: "Gents Toilet Motion Sensor Alarm"
value_template: >-
{{ as_timestamp(states.sensor.date_time.last_changed) - as_timestamp(states.binary_sensor.ping_tuya_motion_sensor_gents_toilet.last_changed) < states('input_number.motion_sensor_idle_secs')|int }}
- platform: ping
host: 192.168.2.61
count: 1
scan_interval: 1
name: ping_tuya_motion_sensor_ladies_toilet
- platform: template
sensors:
tuya_motion_sensor_ladies_toilet:
friendly_name: "Ladies Toilet Motion Sensor Alarm"
value_template: >-
{{ as_timestamp(states.sensor.date_time.last_changed) - as_timestamp(states.binary_sensor.ping_tuya_motion_sensor_ladies_toilet.last_changed) < states('input_number.motion_sensor_idle_secs')|int }}
so I never managed to get two of these sensors working, but I did manage to come up with another way of interacting with the basic ping sensor - and it seems to work! it’s not as pretty as @angadsingh 's original solution, but it’s been reliable for a few days now, and has let me add counters etc.
I read a great post about “debouncing” a binary sensor, which meant the 5-8 ping responses I get from the Tuya motion sensor are evened out. here’s the original article:
https://community.home-assistant.io/t/debouncing-binary-sensory/111833/5
from this I created the following sensors:
timer:
gents_ping_motion_latch:
duration: '00:01:00'
input_boolean:
gents_ping_motion_latch:
initial: off
then I needed a whole bunch of automation - but it worked! the main automation times an RGB bulb moving between Red Amber Green depending on when someone last visited. I needed a couple of other automations as well to reset the timer for the debouncer, but it works!
- id: '1595074710698'
alias: Gents timer automation
description: ''
trigger:
- entity_id: binary_sensor.ping_tuya_motion_sensor_gents_toilet
from: 'off'
platform: state
to: 'on'
condition:
- condition: state
entity_id: input_boolean.gents_ping_motion_latch
state: 'off'
action:
- data: {}
entity_id: input_boolean.gents_ping_motion_latch
service: input_boolean.turn_on
- data: {}
entity_id: input_number.gents_isbusy_counter
service: input_number.increment
- data: {}
entity_id: timer.gents_ping_motion_latch
service: timer.start
- scene: scene.gents_red
- delay: 00:01:00
- scene: scene.gents_amber
- delay: 00:01:00
- scene: scene.gents_green
- id: '1595077977474'
alias: Gents Motion latch timer finished
description: ''
trigger:
- event_data:
trigger:
- event_data:
entity_id: timer.gents_ping_motion_latch
event_type: timer.finished
platform: event
event_type: timer.finished
platform: event
condition: []
action:
- data: {}
entity_id: input_boolean.gents_ping_motion_latch
service: input_boolean.turn_off
And that’s it - I couldn’t have got it working without the ping binary sensor, but for me, once I had 2 sensors defined, the second one always stayed on. with this automation I managed to set the two things up.
Just thought I’d post this in case anyone else got stuck, I’m still new to HomeAssistant, but I thought that maybe someone could benefit from my week of troubleshooting.