FAQ - How do I use the sensors in custom actions
Below are some examples on how to use the custom actions to send a message. To do this add action / call service / start typing “Notifications” in the service text box and select your mobile device. Add a title and in the message copy one of the sensors an paste it in. Then keep editing.
1 - Use of sensors names in a message.
You just replace the sensor name to the one you would like to use.
service: notify.mobile_app_blacky_iphone
data:
title: Low Battery Notification
message: "{{sensors_names}} all have a low battery level and it is time to replace them"
2 - This will report the sensors one after the other
You just replace the sensor name to the one you would like to use.
service: notify.mobile_app_blacky_iphone
data:
title: Low Battery Notification
message: "{{all_sensors}}"
They will be like this in your message;
sensor 1, sensor 2, sensor 3, etc
3 - This will use a new line per sensor
You just replace the sensor name to the one you would like to use.
service: notify.mobile_app_blacky_iphone
data:
title: Low Battery Notification
message: "{{all_sensors|replace(', ', '\n')}}"
They will be like this in your message;
sensor 1
sensor 2
sensor 3
etc
4 - This will use a new line per sensor using two sensors
You just replace the sensor name to the one you would like to use.
message: "{{all_sensors|replace(', ', '\n')}}{{'\n'}}{{all_sensors_custom_group|replace(', ', '\n')}}"
They will be like this in your message;
all_sensor 1
all_sensor 2
all_sensor 3
etc
all_sensors_custom_group 1
all_sensors_custom_group 2
etc
5 - These are conditions for checking if there are any sensors to report
You just replace the sensor name to the one you would like to use.
This one will check if there are any sensors and if none then it will be true.
{{ all_sensors == '' }}
This one will check if there are any sensors and if there are some to report then it will be true.
{{ not all_sensors == '' }}
6 - This is an “if / then + else” action
This example is if you would like to receive a okay confirmation message if there are no batteries to report and if there are batteries to report it will list them.
You just replace the sensor name to the one you would like to use.
First we select a ‘If-then’ action. Click ‘+ ADD ACTION’, then start typing ‘If-then’ and the action will pop up… select it.
Then add the condition by adding in a template condition to check if there are any sensors to notify. Click ‘+ ADD CONDITION’, then type ‘template’ and select it. Then add the code below.
Note: See example 5 above for condition explanation.
{{ all_sensors == '' }}
If the condition was true (no sensors to report) then we send this okay confirmation message. In ‘Then’, Click on ‘+ ADD ACTION’, then type ‘notification’ and select the notification you would like.
If the condition was false (sensors to report) then we send this message with all the sensors that have low battery level. Click on ‘Add else’ then ‘+ ADD ACTION’, then type ‘notification’ and select the notification you would like.
7 - This is an “if / then” action
This example is if you would like to receive a message only when there are low battery sensors to report.
You just replace the sensor name to the one you would like to use.
First we select a ‘If-then’ action. Click ‘+ ADD ACTION’, then start typing ‘If-then’ and the action will pop up… select it.
Then add the condition by adding in a template condition to check if there are any sensors to notify. Click ‘+ ADD CONDITION’, then type ‘template’ and select it. Then add the code below.
Note: See example 5 above for condition explanation.
{{ not all_sensors == '' }}
If the condition was true (sensors to report) then we send this message with all the sensors. In ‘Then’, Click on ‘+ ADD ACTION’, then type ‘notification’ and select the notification you would like.
NOTE: If there was no sensor to report then we wouldn’t get a message.
8 - If you would like to have a bullet point or any other symbol before each sensor
You just replace the sensor name to the one you would like to use.
message: |-
• {{all_sensors|replace(', ', '
• ')}}
or
message: "• {{all_sensors|replace(', ', '\n• ')}}"
9 - If you would like to have a bracket around the battery %, Low reading and unavailable
You just replace the sensor name to the one you would like to use.
You don’t have to use every “replace” as it just depending on what sensor you are using and how you construct your message, but it will give you some information / guide on what you can do.
message: "{{all_sensors|replace('@ ', '(')|replace('is ', '(')|replace(', ', ')\\n')}})"
Enjoy
Blacky
Back to FAQ: Click Here