Frenchdom
(Dom (OH 3.2 FINAL on Pi4, full Zigbee via MQTT))
1
Hi, this is my first post on my solutions. Excuse my english for I’m French.
Here’s a rule to send / receive a mail, at 7AM and 7PM, with battery status (< 30% in this example) and alerts on devices which were not seen for a certain amount of time (over 60 minutes in this example).
rule "Controle capteurs"
when
Time cron "0 0 7,19 ? * * *"
then
VarTest=""
/////////////// Long last seen items ////////////////////
VarTest=VarTest + "\n__________________________________________________________________________________\n\nFollowing items have not been seen for a long time : \n__________________________________________________________________________________"
G_Devices_Updates?.members.sortBy[ name ].forEach[ profile |
VarTest = VarTest + "\n" + "\n" + "---------- " + profile.label + " ----------"
// get group object
val gProfile = G_Devices_Updates.members.filter[ p | p.name == profile.name ].head as GroupItem
// now loop through all items in the profile
gProfile.members.filter(item|((item.state != NULL) && (Duration.between((item.state as DateTimeType).getZonedDateTime(), ZonedDateTime.now()).toMinutes()) > 60 )).sortBy[ label ].forEach[item | VarTest = VarTest + "\n" + item.label + " - " + (Duration.between((item.state as DateTimeType).getZonedDateTime(), ZonedDateTime.now()).toMinutes()) + " mn"]
VarTest=VarTest + "\n"
gProfile.members.filter(item|(item.state == NULL)).sortBy[ label ].forEach[item | VarTest = VarTest + "\n" + item.label + " - Jamais vu !"]
]
logInfo("My Rule", VarTest)
/////////////// Weak batteries ////////////////////
VarTest=VarTest + "\n\n\n__________________________________________________________________________________\n\nFollowing batteries are weak : \n__________________________________________________________________________________"
G_Batteries?.members.sortBy[ name ].forEach[ profile |
VarTest = VarTest + "\n" + "\n" + "---------- " + profile.label + " ----------"
// get group object
val gProfile2 = G_Batteries.members.filter[ p | p.name == profile.name ].head as GroupItem
// now loop through all items in the profile
gProfile2.members.filter(item|((item.state != NULL) && (item.state < 30 ))).sortBy[ label ].forEach[item | VarTest = VarTest + "\n" + item.label + " - Charge : " + item.state + "%"]
VarTest= VarTest + "\n"
gProfile2.members.filter(item|(item.state == NULL)).sortBy[ label ].forEach[item | VarTest = VarTest + "\n" + item.label + " - Jamais vu !"]
]
logInfo("My Rule", VarTest)
/////////////// Send mail ////////////////////
val mailActions = getActions("mail","mail:smtp:googlesmtp")
mailActions.sendHtmlMail("xxxxxxx@xxxxx.com", "Capteurs non actifs", VarTest)
end
The rule goes through included groups in a master group. Example for Batteries group :
///////////////////////////// Niveaux batteries /////////////////////////////////
Group G_Batteries "Etat batteries" <battery>
Group G_Sensor_Batteries "Batteries capteurs" <battery> (G_Batteries)
Group G_Contact_Batteries "Batteries contacts" <battery> (G_Batteries)
Group G_Motion_Batteries "Batteries motion sensors" <battery> (G_Batteries)
Group G_Switch_Batteries "Batteries switches" <battery> (G_Batteries)
Group G_Thermostat_Batteries "Batteries thermostats" <battery> (G_Batteries)