šŸŖ« Low Battery Notifications & Actions

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 == '' }}

2

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.

4

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 == '' }}

6

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.

5

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 :grinning:

Back to FAQ: Click Here

4 Likes