Hi
Im trying to read a PIR sensor that is directly connected to my raspberry pi.
When it is sensing motion it writes ‘On’ to a .txt file, when there is no motion it writes ‘Off’.
On HA i use a sensor template to read if there is motion or not.
Now i want to add an automation to it.
So when the .txt file has ‘On’, it has to turn on my switch.light.
But i think the problem is with the .txt file.
Does the automation have to read a string?
Or how can i fix it ?
- id: 'xxxxxxxxxxxxxx'
alias: Test Pir
trigger:
- entity_id: sensor.motion
from: '"Off"'
platform: state
to: '"On"'
condition: []
action:
- condition: state
entity_id: switch.light
state: 'On'
Greetings
Is sensor.motion’s state On
or is it "On"
? I.e., does the state actually contain double quotes? If not, then your trigger should probably change to:
trigger:
- entity_id: sensor.motion
from: 'Off'
platform: state
to: 'On'
Next, your action contains only one step which is a condition. I.e., it tests to see if switch.light’s state is ‘On’. If it isn’t it aborts. But if it is it goes on to do nothing, because there is no next step. I think this is what you want for your action part:
action:
service: switch.turn_on
entity_id: switch.light
1 Like
Doesn’t that take too long until the automation triggers?
Is this a DIY sensor?
That did the magic, the only thing i see is that my pi is throwing some errors like a Time sync error.
After a while i couldn’t reach the pi anymore using a ping request.
So is HA not strong enough to constantly read a txt file?