I’m trying to use a Rule as a global function but I need to be able to detect if the value of ItemName.state is a String or a Number (to act accordingly)
I’m trying to create a sort of Global Function (to broadcast notifications) that other rules can call, and I want to be able to send either Strings (ie “Presence Detected”) or Numbers (ie 1). So the rule needs to know if the state received is a Number in order to map it to the respective string with a transform.
In short, I was not able to figure-out a way to detect if a string state contains just a number.
As far as I understand I can not create functions inside the rules.
Create 2 items, one a String item and the other a Number item
Create a rule where the trigger is one of these 2 items received command
In the rule select the source with the implicit variable triggeringItem
String myString
Number myNumber
rule "send notification"
when
Item myString received command or
Item myNumber received command
then
if (triggeringItem.name == "myString") {
// Send String notification
} else {
// Send Number notification
}
end
Thanks for the ideas! For my particular use case I ended up breaking the logic into two Rules, one (master) that only deals with Strings, and another that transform the Number into a String before forwarding to the master rule.