Make text in Mail Notifyer Automation conditional

Hi,
Need a little help… I use the Email Notifier for sending periodic messages from Automations. But I want to make the content of the mail conditional.

Below I report weekly the battery status of 5 sensors.

I’d like to add ‘OK’ or ‘NOK’ before the text “Battery level”, but I don’t succeed in getting the code right. Anyone with a little help?

Thanks!

alias: Weekly overview battery
description: ""
triggers:
  - trigger: time
    at: "23:59:00"
    weekday:
      - fri
conditions: []
actions:
  - action: email_notifier.send
    metadata: {}
    data:
      account: MASKED
      recipients: MASKED
      title: Overzicht batterijstatus
      message: >-
        Battery level : {{
        states("sensor.hue_motion_sensor_1_batterij") }}
        Battery level : {{
        states("sensor.hue_motion_sensor_2_batterij") }}
        Battery level : {{
        states("sensor.hue_motion_sensor_3_batterij") }}
        Battery level : {{
        states("sensor.hue_motion_sensor_4_batterij") }}
        Battery level : {{
        states("sensor.hue_motion_sensor_5_batterij") }}
mode: single

Sure if you actually tell us when you want one or the other. i.e. how to decide which one you want?

Hi, I want to add the OK / NOK based on the sensor.hue_motion_sensor_#batterij being below 15. So, when sensor-value is above or equal to 15 add ‘OK’ to the text, and when sensor-value is below 15 add ‘NOK’.
In pseudo-code:
IF sensor.hue_motion_sensor
#_batterij >=
THEN
“OK”
ELSE
“NOK”
END_IF

      message: >
        {{ 'NOK' if states("sensor.hue_motion_sensor_1_batterij")|float(0) < 15 else 'OK' }} Battery level : {{
        states("sensor.hue_motion_sensor_1_batterij") }}
        {{ 'NOK' if states("sensor.hue_motion_sensor_2_batterij")|float(0) < 15 else 'OK' }} Battery level : {{
        states("sensor.hue_motion_sensor_2_batterij") }}
        {{ 'NOK' if states("sensor.hue_motion_sensor_3_batterij")|float(0) < 15 else 'OK' }} Battery level : {{
        states("sensor.hue_motion_sensor_3_batterij") }}
        {{ 'NOK' if states("sensor.hue_motion_sensor_4_batterij")|float(0) < 15 else 'OK' }} Battery level : {{
        states("sensor.hue_motion_sensor_4_batterij") }}
        {{ 'NOK' if states("sensor.hue_motion_sensor_5_batterij")|float(0) < 15 else 'OK' }} Battery level : {{
        states("sensor.hue_motion_sensor_5_batterij") }}
1 Like

Super/Thanks! The syntax is a bit different as I’m used.

There are other ways to do it, e.g. Templating - Home Assistant