Hi -
I want to cast the value of a global variable with the rule machine. Even though the variable has a value, it displays/casts as null. I tried different global variables (strings and numbers) and always got the same result. Any idea if I can cast the value of the variable somehow?
Tnx!
Can you define cast? You mean casting as in development (boxing/unboxing) or casting as in a notification?
Also, how are you setting the variable? Posting a screen cap of the rule will help.
I am going to make an assumption here, because I think I have the same "bug".
I have a rule in RM4 that notifies me if both people are away, and a door is unlocked. I have %device% in the rule to notify me via the Hubitat app.
I get something like "Device ""null"" is unlocked" on my phone.
Is it something like this serg123?
The %device% variable is the triggering device of the rule. So, if you are setting a global variable in one rule and then using that variable to send a notification in another rule %device% will no longer be correct. You would need to set the %device% variable equal to another global variable in the rule that was triggered by that device.
If you provide a screenshot of your rule, that would be helpful in seeing what the problem might be and what workaround could be implemented. Without the rule itself we're just talking generalities.
I meant cast as in sending a notification. Both my cell phone and google home devices display/say "null".
Here are the rule actions
Set %CAST-MESSAGE% to 'Test'
Notify Pixel 2 XL and Speak on House: '%CAST-MESSAGE%'
Take the "-" out of your variable name and try again.
Update, I just created a rule with the exact same actions and it worked perfectly.
Can you send a notification from the edit device page within Hubitat.
1 Like
Notification from the device page works fine.
I tried removing the dash from the variable name but still get 'null' when running the action (I have other global variable names with dash -- but apparently that doesn't matter based on your test).
Yeah. Before you ran the actions for that rule, did you hit "update rule"? Can you show a screenshot of the rule?
Yes, I did hit 'update rule'. How do I attach a screenshot? I keep getting "Sorry, you can't put images in a post" once I attach and hit reply.
Here are my current actions
Set %CASTMESSAGE% to 'Test message'
Notify Pixel 2 XL and Speak on House: '%CASTMESSAGE%'
Log: Message is: %CASTMESSAGE%
And this what the log shows
[app:140]2019-10-09 12:45:07.004 pm [info] Message is: null
[app:140] 2019-10-09 12:45:06.975 pm [info] Action: Log: Message is: %CASTMESSAGE%
[app:140] 2019-10-09 12:45:06.870 pm [info] Action: Notify Pixel 2 XL and Speak on House: '%CASTMESSAGE%'
[app:140] 2019-10-09 12:45:06.724 pm [info] Action: Set %CASTMESSAGE% to 'Test message'
Something odd is going on with my variables. I tried other variables as well, but I am getting the same result.
Can you show a screenshot of your Global Variable Setup page?
@Ryan780 He is a new user and can't post images.
Sent you a PM. If you can't post an image here, see if you can send one there.
Maybe try removing the percent symbols when setting the variable? In @Ryan780's example, the percent symbols are only used in the notification, not in setting the variable to a value.
When setting the variable you pick it from a drop-down. It's not free text. But that does bring up the question....the name of your global variable is just CASTMESSAGE, right? The name isn't defined as %CASTMESSAGE%. That was one of the reasons I wanted to see the global variable's definition page.
1 Like
Okay, problem solved. I was using a % when creating the variable name. It's working fine now, using the % only when referencing the variable in the text box.
Thanks a lot!
2 Likes
Tagging @bravenel - Bruce, is there any way you can prevent users from naming a RM Variable with a percent symbol in the name? This would help to avoid this issue in the future.
2 Likes