Automation from YAML to Node-Red

Hi, here is a little yaml automation. I hope that someone can translate it in Node-Red to best understand how it works.
The automation notify once a day via Telegram fi the tablet battery is below a minimal value.
Furthermore, the automation work only if is set to 'on' the flag "enabled-notification".
In Home Assistant I have defined the follow input:

  • input_number.minlevelbattery

  • last_notify

  • enabled_notification

  • alias: "Low tabet battery"
    trigger:
    platform: template
    value_template: '{{ states.sensor.battery_tablet.state | float < (states.input_number.minlevelbattery.state | float) }}'

    condition:

    • condition: template
      value_template: "{{ states.input_datetime.last_notify.state != states.sensor.date.state }}"

    • condition: numeric_state
      entity_id: sensor.battery_tablet
      above: 10

    • condition: state
      entity_id: input_boolean.enabled_notification
      state: 'on'

    action:

    • service: input_datetime.set_datetime
      entity_id: input_datetime.last_notify
      data_template:
      date: "{{ states.sensor.date.state | timestamp_custom('%Y-%m-%d') }}"

    • service: notify.telegram
      data:
      message: "Tablet battery low: {{ states.sensor.battery_tablet.state }} %"

You learn by reading and doing.

There is excellent documentation available on this site.

Do you want to keep home assistant as a source ?
Or do you want node-red to handle everything ?
Where is the 'enabled-notification' coming from, same question for the battery level.

Yes, I want to keep home assistant as a source.
"enabled-notification'" is an "input_boolean" of Home Assistant
and "battery_level" is an "input_number" of Home Assistant.
My difficulty is in put two or more entity of Home Asistant in the same node to make a test. I would like to see an example

There are various approaches to create this in node-red.

If you receive messages from HA, I would keep track of the notification state and battery level in flow variables.

Example

Example flow:

[{"id":"f06b2439.a8f888","type":"inject","z":"1b5bc2fe.d98add","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":144,"wires":[["e03c1fb5.91462"]]},{"id":"e03c1fb5.91462","type":"change","z":"1b5bc2fe.d98add","name":"","rules":[{"t":"set","p":"notification_enabled","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":432,"y":168,"wires":[[]]},{"id":"56aedbe9.3b1004","type":"comment","z":"1b5bc2fe.d98add","name":"notification enabled input from HA","info":"","x":260,"y":96,"wires":[]},{"id":"93d5e20b.586ea","type":"inject","z":"1b5bc2fe.d98add","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":192,"wires":[["e03c1fb5.91462"]]},{"id":"96f9a889.b5dbd","type":"inject","z":"1b5bc2fe.d98add","name":"","topic":"","payload":"35","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":360,"wires":[["8a60f0a0.6e7338"]]},{"id":"5c91acbd.6d624c","type":"comment","z":"1b5bc2fe.d98add","name":"battery level input from HA","info":"","x":230,"y":312,"wires":[]},{"id":"8a60f0a0.6e7338","type":"change","z":"1b5bc2fe.d98add","name":"","rules":[{"t":"set","p":"battery_level","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":412,"y":384,"wires":[[]]},{"id":"1c256e38.60f8c2","type":"inject","z":"1b5bc2fe.d98add","name":"","topic":"","payload":"6","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":408,"wires":[["8a60f0a0.6e7338"]]},{"id":"fb8a6064.b4c2c","type":"inject","z":"1b5bc2fe.d98add","name":"once a day","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"x":190,"y":576,"wires":[["c28f8bf2.c2f7c8"]]},{"id":"c28f8bf2.c2f7c8","type":"switch","z":"1b5bc2fe.d98add","name":"notification_enabled ?","property":"notification_enabled","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":412,"y":576,"wires":[["6cd35083.59a408"]]},{"id":"1c852b74.98ff4d","type":"comment","z":"1b5bc2fe.d98add","name":"Send notification once a day","info":"","x":240,"y":528,"wires":[]},{"id":"6cd35083.59a408","type":"switch","z":"1b5bc2fe.d98add","name":"battery_level < 10 % ?","property":"battery_level","propertyType":"flow","rules":[{"t":"lt","v":"10","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":652,"y":576,"wires":[["12e92e86.3c0b49"]]},{"id":"9ae3b8ee.26bcc8","type":"debug","z":"1b5bc2fe.d98add","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1058,"y":576,"wires":[]},{"id":"12e92e86.3c0b49","type":"template","z":"1b5bc2fe.d98add","name":"create message","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Tablet battery low: {{msg.payload}}","output":"str","x":872,"y":576,"wires":[["9ae3b8ee.26bcc8"]]}]