I have 5 PIR sensors mounted through Sonoff RF bridge (without tasmota or anything). All sensors are named PIR1, PIR2, and so on…
I want to make an automation which triggers a notification, when any of the PIR sensors are triggered. And for this, I thought that for me, the best way is to do an automation like:
Trigger: state Sonoff RF bridge (if any of PIR sensors are triggered)
Action: Notify
In the middle, I want to put a Condition which will trigger the automation ONLY if the sensor name contains the string “PIR”…
Easiest way would be an MQTT trigger on the top level state topic. But, the sensor names are not included in this message. Only their IDs.
tele/sonoffRF/Result
The alternate is to create your template sensors which receive this data and turn on/off specific sensors. So each of these mqtt sensors will receive the same message, but only the ones its addressed to would turn on/off.
Given you say you have 5 PIR sensors and they are triggered, I’m assuming you are already doing option 2.
So, why not just create an automation that follows those sensors?
trigger:
platform: state
entity_id:
- binary_sensor.pir1
- binary_sensor.pir2
- binary_sensor.pir3
- binary_sensor.pir4
- binary_sensor.pir5
to: 'on'
action:
- service: notify.notify
data:
# Says "PIR1 has been triggered" if it was binary_sensor.pir1 that fired
message: "{{trigger.to_state.object_id}} has been triggered!"
We now know it was a PIR sensor that caused the trigger. No condition needed.
Otherwise, you’ll have to do an MQTT automation and parse the results by ID. You can use variables to make things easier…but it’s kind of redundant to do this if you already have the sensors available.
I don’t use MQTT… I don’t know why, but I find it harder to use because I don’t understand this service and I feel that it is not so directly as the normal usage…
I just made an automation which triggers “State of remote.sonoff_rf_bridge” for the attribute which changes when the sensor is triggered, then I put a condition to get a notification only when PIR 2 is triggered, like {{ state_attr(“remote.sonoff_rf_bridge”, “name”) == “PIR 2”}}
The thing which I want to do, is something like this {{ state_attr(“remote.sonoff_rf_bridge”, “name”) contains “PIR” string}} But I don’t know how…