Hi everyone, im trying to generate a virtual sensor via Groovy rule. I tried @Rich example by coping the code to a new groovy rule with no results. My rule is:
The obvious problem is in the then, Values class and therefore Values.create() no longer exists and now you just supply the value directly; so if it’s a text/string attribute you just need:
FYI: The facts object that is passed into the when closure is of type RulesFacts, you can explore the classes to figure out what is possible from rules, obviously with the full scripting capabilities of groovy there’s no limitations to what can be achieved.
I missed the other problem with your rule which relates to the UPDATE_FREQUENCY if using the string overload of putTemporary then the string must be a valid ISO8601 Duriation (i.e. PT5S).
Lots has changed in the platform since you were able to supply 5s as a duration.
FYI: You can always look at the docker logs for additional information as the Manager UI logs only show limited information
Thanks Rich, the virtual sensor is now working! i would like to check other sensor status, the idea is if the sensor does not report after 5 min, the attribute value goes to disconnected. Is there a way to do that?
when( {facts -> "ATTRIBUTE NOT UPDATED SINCE x TIME"} )
then( {facts -> "CHANGE ATTRIBUTE VALUE TO DISCONNECTED"} )