Using Variables in notifications
-
I'm trying to insert variables into notifications. I've tried
{
"message": "Oil Level is {{Oil_Level_V_to_Percent}}"
}Also prefixing {{ with $ and a few other things.
I get the main body but the variable is missing, i.e "Oil Level Is"
Could someone please help me send the variable (and to title the notification would be great too)
Many thanks
ApologiesHass: v2022.10.4
MSR: latest-22274-24dfd72c -
@cadwizzard first we’d need to know what home controller you are using and what version of MSR.
-
...and if the variable and action is in a Rule (show it) or a Global Reaction (show it). And show the variable definition, be it rule-based or global.
-
Apologies
Initial post updated -
So when you are testing if the actions work using a variable you have to use the big play button that right under the "Set Reaction" title. As for using said variable you're going to want to use it in this form
${{<variable_name>}}
. Since you were likely hitting the play button just for this action that is probably why you werent getting the variable value in your notification.As for adding a title it will look like this
{ "message": "${{Oil_Level_V_to_Percent}}", "title": "<insert title name>" }
-
Cadwizzardreplied to Pabla on Oct 21, 2022, 8:53 AM last edited by Cadwizzard Oct 21, 2022, 4:53 AM
@pabla Thank You!
I was going wrong with the title by missing the comma in preceding line, I had the rest right and indented the same before I took the code out, as it wasn't working.And right again, I had tested the code with ${{content}} but it didn't work - most likely because I used the play button to the right and not above the reaction.
Really appreciated, i've updated my template I copy from, so that should be notifications sorted for everything now.
Seperate issue is the value on the sensor flaps up and down by 1% when its close to changing (temperature in the oil tank/expansion) and sends lots of notifications, just need to figure out how to address that. But off topic for this post
-
@cadwizzard You can use the
round
function for your variable to round it to whatever decimal point you need. Have a look in reactor docs under expressions -> functions for more info -
@pabla The issue isn't rounding, the sensor is in Volts, i multiply by 10 to get % for gauges etc, so it's always rounded.
The issue is due to temperature and the accuracy of the sensor (ultrasonic), when the oil level is very close to for example 55 and 56% (5.5v/5.6v) and the oil expands, the reading will go from 55 to 56 and then 55 and then 56 over and over due to the tiny variance between the two readings. If that makes sense.
I can't set a rule to only track decreasing changes as we also fill up the tank sometimes too -
toggledbitswrote on Oct 24, 2022, 12:18 PM last edited by toggledbits Oct 24, 2022, 8:18 AM
You might consider a bit of time-based hysteresis by using the "sustain for" option in your rule/condition(s). I do this with various things around the house... if the attic humidity is above X% for more than YY minutes, start the dehumidifier, etc. This removes the short-cycling that can occur when a measurement is unstable around a critical point.
Also, there are ways previously documented in Reactor for Vera to do things like one-hour averages and moving averages, which can dampen those bounces/drifts. I'm not sure if anyone has done an MSR version of those, but the general approach is the same.
-
@toggledbits said in Using Variables in notifications:
Also, there are ways previously documented in Reactor for Vera to do things like one-hour averages and moving averages, which can dampen those bounces/drifts. I'm not sure if anyone has done an MSR version of those, but the general approach is the same.
Speaking of this, I'll surely welcome some recipes somewhere. I'll think a curated list will definitely benefit the community. I think it's fair to link reactor ones as well, since expressions are almost similar.
-
@toggledbits I used something like that to dampen solar panel logic. I am not "legally" allowed to hook up, but I still wanted to play with them. I still have a dumb meter and it's easily possible to end up negative for the month. I used a couple of RIB relays to turn panel groups off if the consumption target for the month was trending under what would be considered believable.
(I also turn them off by the driveway entrance sensor logic on the days that I know the meter reader will show up. I don't particularly need an observant reader seeing the meter flying around backward)
-
5/11