Push alert with number of lights turned on?


I’ve just installed OH Cloud Connector and wonder how to send push notification with number of lights turned on at a specific time ie. 10 PM? Can you share some suggestions?

Two things are needed:

  1. A rule to run at 10om → look at the docu in how to create a rule

  2. A script within the role to get the current number of lights turned on → there should be several topics in the form on this question

Maybe start easy, create a rule and send a simple notification (e.g. checking if any light is on or if all lights are off is easier and can be done with grouping all lights)

I already done it.

rule "push"
Time cron "0 6 20 ? * *"
    sendBroadcastNotification("Test 123")

This rule sends notification. I also got an group item, which shows me how many lights are on in my UI.

Group:Switch:OR(ON,OFF)   gLight   "Ligths [%d]"   <light>   (Home)   ["Lighting", "Switchable"]

How to use it in the rules?


Got an error during execution of script:

Script execution of rule with UID ‘dom-3’ failed: An error occurred during the script execution: Could not invoke method: org.openhab.io.openhabcloud.NotificationAction.sendBroadcastNotification(java.lang.String) on instance: null in dom

It should be

sendBroadcastNotification("Światła: " + gLight.state)

But it returns only a value ON.

If it’s returning ON, than the example is correct, because it was intended as an easy example to show how to dynamically build a notification.

If you want to include the number of lights on, there are some examples in the forum on how to get the number of group items for a specific state