Node-Red notification to iphone passing sensor states

Hello,
I always found templating difficult to understand,
but even harder to be used in Node-Red.
I have all my automations in Node-Red but I can’t do this.
Can someone help me convert this home assistant automation into node red automation?

alias: Test
description: ""
trigger:
  - platform: time
    at: "04:30:00"
condition: []
action:
  - service: notify.mobile_app_iphone_13_pro_emp83
    data:
      title: Les Ulis
      message: >-
        Good morning. The current outside temperature is {{    
        states('sensor.balcon_temperature') | float }} °C, humidity is
        {{ states('sensor.balcon_humidity') | float }} % and
        the wind speed is {{ state_attr('weather.ulis', 'wind_speed') }}
        km/h. 
mode: single

Please import this code to nodered and see.

[{"id":"bbd2e723a8fb999e","type":"inject","z":"51045e07.bbf87","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"30 16 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":1700,"wires":[["f54c44cf0d9bddec"]]},{"id":"f54c44cf0d9bddec","type":"api-current-state","z":"51045e07.bbf87","name":"Balcon Temp","server":"d177950.2a5aa68","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.balcon_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"temp","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":310,"y":1700,"wires":[["feada13efa8f411e"]]},{"id":"feada13efa8f411e","type":"api-current-state","z":"51045e07.bbf87","name":"Balcon Humidity","server":"d177950.2a5aa68","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.balcon_humidity","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"humidity","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":480,"y":1700,"wires":[["2905287d40d7526e"]]},{"id":"2905287d40d7526e","type":"api-current-state","z":"51045e07.bbf87","name":"Windspeed.","server":"d177950.2a5aa68","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"weather.ulis","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"wind","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":650,"y":1700,"wires":[["a491e62f07af5b68"]]},{"id":"a491e62f07af5b68","type":"function","z":"51045e07.bbf87","name":"function 1","func":"var speed = msg.wind.attributes.wind_speed\nmsg.payload = \"Good morning. The current outside temperature is \" + msg.temp + \" °C, humidity is \" + msg.humidity + \" % and the wind speed is \" + speed + \" km/h.\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":1700,"wires":[["967b76936ab04709"]]},{"id":"967b76936ab04709","type":"api-call-service","z":"51045e07.bbf87","name":"Iphone Notofication","server":"d177950.2a5aa68","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone_13_pro_emp83","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"Les Ulis\",\"message\":\"{{{payload}}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":970,"y":1700,"wires":[[]]},{"id":"d177950.2a5aa68","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

You will have to select the correct home assistant server.

1 Like

You are the best, is working great.
How about adding more state attributes:

alias: Test
description: ""
trigger:
  - platform: time
    at: "04:30:00"
condition: []
action:
  - service: notify.mobile_app_iphone_13_pro_emp83
    data:
      message: >-
        Good morning.      The current outside temperature is {{    
        states('sensor.balcon_temperature') | float }} °C, humidity is {{    
        states('sensor.balcon_humidity') | float }} % and the wind speed is of
        {{     state_attr('weather.forecast_home_les_ulis', 'wind_speed') }}
        km/h.      The current weather is {{
        state_attr('weather.forecast_home_les_ulis', 'forecast') [0].condition
        }} and the weather global throughout the day is {{
        states('weather.forecast_home_les_ulis') }}.     The minimum temperature
        for tomorrow is {{ state_attr('weather.forecast_home_les_ulis',
        'forecast') [0].templow }}
mode: single

You just need to add the current state node for the entity and build payload in function node. Please try this.

[{"id":"2905287d40d7526e","type":"api-current-state","z":"51045e07.bbf87","name":"Windspeed.","server":"d177950.2a5aa68","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"weather.ulis","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"wind","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":710,"y":1740,"wires":[["2e160d8f95abe370"]]},{"id":"feada13efa8f411e","type":"api-current-state","z":"51045e07.bbf87","name":"Balcon Humidity","server":"d177950.2a5aa68","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.balcon_humidity","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"humidity","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":540,"y":1740,"wires":[["2905287d40d7526e"]]},{"id":"2e160d8f95abe370","type":"api-current-state","z":"51045e07.bbf87","name":"Windspeed.","server":"d177950.2a5aa68","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"weather.forecast_home_les_ulis","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"fore","propertyType":"msg","value":"","valueType":"entity"},{"property":"utlis","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":870,"y":1740,"wires":[["a491e62f07af5b68"]]},{"id":"f54c44cf0d9bddec","type":"api-current-state","z":"51045e07.bbf87","name":"Balcon Temp","server":"d177950.2a5aa68","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.balcon_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"temp","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":370,"y":1740,"wires":[["feada13efa8f411e"]]},{"id":"a491e62f07af5b68","type":"function","z":"51045e07.bbf87","name":"function 1","func":"var speed = msg.wind.attributes.wind_speed\nvar fore = msg.fore.attributes.forecast[0].condition\nvar utlis = msg.utlis\nvar mini = msg.fore.attributes.forecast[0].templow\nmsg.payload = \"Good morning. The current outside temperature is \" + msg.temp + \" °C, humidity is \" + msg.humidity + \" % and the wind speed is \" + speed + \" km/h.      The current weather is \" + fore + \" and the weather global throughout the day is \" + utlis + \".     The minimum temperature for tomorrow is \" + mini\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":1740,"wires":[["967b76936ab04709"]]},{"id":"bbd2e723a8fb999e","type":"inject","z":"51045e07.bbf87","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"30 16 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":1740,"wires":[["f54c44cf0d9bddec"]]},{"id":"967b76936ab04709","type":"api-call-service","z":"51045e07.bbf87","name":"Iphone Notofication","server":"d177950.2a5aa68","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone_13_pro_emp83","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"Les Ulis\",\"message\":\"{{{payload}}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1190,"y":1740,"wires":[[]]},{"id":"d177950.2a5aa68","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like
{"message": "Good morning. The current outside temperature is " &
 $entities("sensor.balcon_temperature").state & " °C, humidity is " & $entities("sensor.balcon_humidity").state &
 " % and the wind speed is of " & $entities("weather.forecast_home_les_ulis").attributes.wind_speed &
 " km/h. The current weather is " & $entities("weather.forecast_home_les_ulis").attributes.forecast[0].condition &
 " and the weather global throughout the day is " & $entities("weather.forecast_home_les_ulis").state & ". The minimum temperature for tomorrow is " & $entities("weather.forecast_home_les_ulis").attributes.forecast[0].templow 
 }
1 Like

Thank you, it is working great!

Can you elaborate please?

You can use the above inside the data field of the call-service node.

1 Like

I’ll give it a try.
Thank you.