Use data_template in notify (node-red)

Iam using the render_template node to render this:

message: >
  {% set w = expand('binary_sensor.fenster') | selectattr('state', 'eq', 'on')
  | map(attribute='name') | list %} Es regnet und folgende Fenster sind offen:
  {{ w | join(', ') }}
  data:
    image: /local/media/rain.jpeg

to this:

message: >
   Es regnet und folgende Fenster sind offen:
  HWR
  data:
    image: /local/media/rain.jpeg

Now the question i have:
how to use that output in the ha.notify node? Iam totally new to nodered and converting a lot of my automations right now and this is the first time iam struggle because iam using jinja tempaltes here… :smiley:

In the data section of the call service

{
   "title": "your title here",
   "message": "your message here",
   "data":{
       "image": "image path here"
   }
}

If you set the data field to J expression, you can send the value using the message path. If the message was in payload.message and the image in payload.image you would use

{
   "title": "your title here",
   "message": payload.message,
   "data":{
       "image": payload.image
   }
}

1 Like

In NR the easiest way would be to get the open windows using the get-entities nodes and then format them for the service call.

[{"id":"dc5bf993312e5015","type":"inject","z":"c89d915bdff0f798","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":186,"y":992,"wires":[["2aa68e6f8e599646"]]},{"id":"2aa68e6f8e599646","type":"ha-get-entities","z":"c89d915bdff0f798","name":"get open windows","server":"","version":1,"rules":[{"property":"state","logic":"is","value":"on","valueType":"str"},{"property":"entity_id","logic":"in_group","value":"binary_sensor.fenster","valueType":"str"}],"outputType":"array","outputEmptyResults":false,"outputLocationType":"msg","outputLocation":"payload","outputResultsCount":1,"x":378,"y":992,"wires":[["4ddf93b99f250ecb"]]},{"id":"4ddf93b99f250ecb","type":"split","z":"c89d915bdff0f798","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":558,"y":992,"wires":[["98ba6e6719bfa208"]]},{"id":"98ba6e6719bfa208","type":"template","z":"c89d915bdff0f798","name":"get friendly name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":730,"y":992,"wires":[["67c7313daab1c7e0"]]},{"id":"67c7313daab1c7e0","type":"join","z":"c89d915bdff0f798","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":", ","joinerType":"str","useparts":true,"accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":898,"y":992,"wires":[["89c320e74dc83fb4"]]},{"id":"89c320e74dc83fb4","type":"api-call-service","z":"c89d915bdff0f798","name":"","server":"","version":5,"debugenabled":false,"domain":"notify","service":"person","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"message\": \"It is raining and the following windows are open:\" & payload,\t   \"data\": {\"image\": \"/local/media/rain.jpg\"}\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1050,"y":992,"wires":[[]]},{"id":"e75c30d5d1bd5986","type":"inject","z":"c89d915bdff0f798","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":188,"y":1040,"wires":[["41ef334d8bee6fb3"]]},{"id":"41ef334d8bee6fb3","type":"ha-get-entities","z":"c89d915bdff0f798","name":"get open windows","server":"","version":1,"rules":[{"property":"state","logic":"is","value":"on","valueType":"str"},{"property":"entity_id","logic":"in_group","value":"binary_sensor.fenster","valueType":"str"}],"outputType":"array","outputEmptyResults":false,"outputLocationType":"msg","outputLocation":"payload","outputResultsCount":1,"x":380,"y":1040,"wires":[["29bcdcaf951a615d"]]},{"id":"29bcdcaf951a615d","type":"api-call-service","z":"c89d915bdff0f798","name":"","server":"","version":5,"debugenabled":false,"domain":"notify","service":"person","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"message\": \"It is raining and the following windows are open: \" & $join(payload.attributes.friendly_name, \", \"),\t   \"data\": {\"image\": \"/local/media/rain.jpg\"}\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":582,"y":1040,"wires":[[]]}]
1 Like

I will play around with both approaches. Thanks so far. But now it’s sleepy time:D

okay, i tried the second approach and i got everything working, apart from the image.

Aaaand solved, had ad mistake in the name ending…

here is my final result:

[{"id":"77a05d4a5da05a41","type":"server-state-changed","z":"de120d16f1b6e976","name":"Regen?","server":"323973a0.b6489c","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.gw1100a_rain_rate","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"0","ifStateType":"num","ifStateOperator":"gt","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":230,"y":160,"wires":[["2aa68e6f8e599646"],[]]},{"id":"dc5bf993312e5015","type":"inject","z":"de120d16f1b6e976","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":240,"wires":[["2aa68e6f8e599646"]]},{"id":"2aa68e6f8e599646","type":"ha-get-entities","z":"de120d16f1b6e976","name":"get open windows","server":"323973a0.b6489c","version":1,"rules":[{"property":"entity_id","logic":"in_group","value":"binary_sensor.fenster","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"outputType":"array","outputEmptyResults":false,"outputLocationType":"msg","outputLocation":"payload","outputResultsCount":1,"x":410,"y":160,"wires":[["4ddf93b99f250ecb"]]},{"id":"4ddf93b99f250ecb","type":"split","z":"de120d16f1b6e976","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":570,"y":160,"wires":[["98ba6e6719bfa208"]]},{"id":"98ba6e6719bfa208","type":"template","z":"de120d16f1b6e976","name":"get friendly name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":730,"y":160,"wires":[["67c7313daab1c7e0"]]},{"id":"67c7313daab1c7e0","type":"join","z":"de120d16f1b6e976","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":", ","joinerType":"str","useparts":true,"accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":890,"y":160,"wires":[["89c320e74dc83fb4"]]},{"id":"89c320e74dc83fb4","type":"api-call-service","z":"de120d16f1b6e976","name":"","server":"323973a0.b6489c","version":5,"debugenabled":true,"domain":"notify","service":"mobile_app_imopp","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"message\": \"Es regnet und folgende Fenster sind offen: \" & payload,\t   \"data\": {\"image\": \"/local/media/rain.jpeg\"}\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1070,"y":160,"wires":[[]]},{"id":"323973a0.b6489c","type":"server","name":"Home Assistant","addon":true}]