Automation Help utilising template

The Goal

I am trying to make automation in nodeRed that checks if any doors are left open when the house is unoccupied and sends a critical notification on repeat until it is deactivated or the door is shut. Additionally, it checks if Emma is at St John Payne and will not send notifications to her device if this is true.


The automation does not need to be in nodeRed but I find it a lot easier to use. However, it seems I am unable to use my template {{ states(‘sensor.which_door_open’) }} in NodeRed.

Is there any way I can use my template in NodeRed? or is creating the automation in HA the only way forward (or the most logical). I tried to create the automation in HA but I struggled with the critical notification part and also the condition where not to send notifications to Emma if she is at St John Payne.

NodeRed Flow

[{"id":"fa2b06ee616bb15c","type":"trigger-state","z":"de021acf82478f00","name":"Switch off home automation","server":"4e7f96b.0675968","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_boolean.is_jake_home","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":1,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":true,"x":180,"y":460,"wires":[["fe139629b4a27abf"],[]]},{"id":"1cb9ef74c1c71dbd","type":"trigger-state","z":"de021acf82478f00","name":"Leaving home automation","server":"4e7f96b.0675968","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_boolean.leaving_home","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":190,"y":340,"wires":[["fe139629b4a27abf"],[]]},{"id":"fe139629b4a27abf","type":"api-current-state","z":"de021acf82478f00","name":"","server":"4e7f96b.0675968","version":3,"outputs":2,"halt_if":"closed","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.which_door_open","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","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":580,"y":360,"wires":[[],["e934a06221137d4f","99822d03a1db0e73"]]},{"id":"e934a06221137d4f","type":"api-call-service","z":"de021acf82478f00","name":"front door is open notification - jake - critical ","server":"4e7f96b.0675968","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_jakes_11_max_pro","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"Security Alert!\",\"message\":\"The {{ states('sensor.which_door_open') }} is open\",\"data\":{\"push\":{\"sound\":{\"name\":\"default\",\"critical\":1,\"volume\":1}}}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"payload","output_location_type":"none","x":990,"y":300,"wires":[["2e23555d1b4c9c1d"]]},{"id":"98599c5294486fc7","type":"inject","z":"de021acf82478f00","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":220,"wires":[["fe139629b4a27abf"]]},{"id":"497362f15f990d9d","type":"api-call-service","z":"de021acf82478f00","name":"front door is open notification - em - critical ","server":"4e7f96b.0675968","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone_57","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"Security Alert!\",\"message\":\"The {{ states('sensor.which_door_open') }} is open\",\"data\":{\"push\":{\"sound\":{\"name\":\"default\",\"critical\":1,\"volume\":1}}}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"payload","output_location_type":"none","x":1230,"y":500,"wires":[[]]},{"id":"99822d03a1db0e73","type":"api-current-state","z":"de021acf82478f00","name":"","server":"4e7f96b.0675968","version":3,"outputs":2,"halt_if":"St John Payne","halt_if_type":"str","halt_if_compare":"is","entity_id":"person.emma","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","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":960,"y":380,"wires":[[],["497362f15f990d9d"]]},{"id":"bf0af7488ab21468","type":"delay","z":"de021acf82478f00","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":760,"y":140,"wires":[["4f0feacbdcc40f33"]]},{"id":"2e23555d1b4c9c1d","type":"api-call-service","z":"de021acf82478f00","name":"Door open crit notify","server":"4e7f96b.0675968","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.door_open_crit_notify"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1020,"y":200,"wires":[["bf0af7488ab21468"]]},{"id":"4f0feacbdcc40f33","type":"api-current-state","z":"de021acf82478f00","name":"Door open crit notify","server":"4e7f96b.0675968","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.door_open_crit_notify","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","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":540,"y":220,"wires":[["fe139629b4a27abf"],[]]},{"id":"4e7f96b.0675968","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Change to the data field type of the call-service node to J: expression

{
    "title": "Security Alert!",
    "message": "The " & $entities("sensor.which_door_open").state & " is open",
    "data": {
        "push": {
            "sound": {
                "name": "default",
                "critical": 1,
                "volume": 1
            }
        }
    }
}

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/call-service.html#data-field

1 Like

Thank you very much.

I seem to be having a weird issue. This JSON works as expected:

{
  "title": "House Alert!",
  "message": "It is raining and you have washing on the line",
  "data": {
    "actions": [
      {
        "action": "washing_on_line_ios",
        "title": "test1",
        "icon": "sfsymbols:bell"
      }
    ],
    "push": {
      "sound": {
        "name": "default",
        "critical": 1,
        "volume": 1
      }
    }
  }
}

However, if I insert the message "The " & $entities("sensor.which_door_open").state & " is open" in this JSON:

{
    "title": "House Alert!",
    "message": "The " & $entities("sensor.which_door_open").state & " is open",
    "data": {
        "actions": [
            {
                "action": "door_open_crit_noti_ios",
                "title": "test1",
                "icon": "sfsymbols:bell"
            }
        ],
        "push": {
            "sound": {
                "name": "default",
                "critical": 1,
                "volume": 1
            }
        }
    }
}

I get API error and when I open it back up I get a syntax error. The only data I am changing is the message.

What is the error? Where are you using this? Do you have the field type set to JSONata, J: expression?

Did you change the data field type?

I didn’t but I did not chnage it when editing other nodes :man_facepalming: sorry guys :flushed: