I’m using NR to monitor power from Shelly PlugS. Because of power variability and my limited NR’s knowledge at time of doing this I wrote simple JS function which evaluates input data. Likely it’s possible to do tgat other way. But it works.
When finished, NR sends notification to mobile phones of persons who are at home.
Besides of that, the flow creates new binary sensor just for presentation purposes in Lovelace.
It’s bit different than you need but I can share the code if you want
text_sensor:
# Device Activity State
# e.g. shows as active if power reading above a certain threshold
- platform: template
name: "${friendly_name} Activity State"
icon: "mdi:${main_icon}"
lambda: |-
if (id(power).state >= $activity_threshold) {
return {"Active"};
} else {
return {"Idle"};
}
update_interval: 5s
threshold can be adjusted in substitutions.
# Substitutions
substitutions:
# Device Names
device_name: "###"
friendly_name: "###"
# Icon
main_icon: "power-socket-uk"
# Default Relay State
# Aka: `restore_mode` in documentation
# Options: `RESTORE_DEFAULT_OFF`, `RESTORE_DEFAULT_ON`, `ALWAYS_ON` & `ALWAYS_OFF`
default_state: "ALWAYS_ON"
# Activity State Threshold
# Threshold (number) that the device will change from `Idle` to `Active` if power is greater than or equal to
activity_threshold: "5"