Mustache-templates

I am trying to get the entity_id using the mustache templates:
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html

Below is the complete msg object. I used {{data.entity_id}}, but it seems not working. what should be the correct syntax?

Thanks.

{"topic":"binary_sensor.wyzesense_xx","payload":"on","data":{"entity_id":"binary_sensor.wyzesense_xx","old_state":{"entity_id":"binary_sensor.wyzesense_xx","state":"off","attributes":{"mac":"xx","device_class":"door","timestamp":"2020-03-13T09:56:26.344000","rssi":-85,"battery_level":90,"friendly_name":"wyze_garage_2"},"last_changed":"2020-03-13T16:39:12.563057+00:00","last_updated":"2020-03-13T16:39:12.563057+00:00","context":{"id":"807bada67c154240a8882d3ad1911480","parent_id":null,"user_id":"676d91a974a74369be71d93d109d6b4a"}},"new_state":{"entity_id":"binary_sensor.wyzesense_xx","state":"on","attributes":{"mac":"xx","device_class":"door","timestamp":"2020-03-13T09:56:26.344000","rssi":-85,"battery_level":90,"friendly_name":"wyze_garage_2"},"last_changed":"2020-03-13T16:39:16.285093+00:00","last_updated":"2020-03-13T16:39:16.285093+00:00","context":{"id":"78e89981ca414c009da2b7f6aae13a61","parent_id":null,"user_id":"676d91a974a74369be71d93d109d6b4a"},"timeSinceChangedMs":11}},"_msgid":"d6d93385.5a59d"}

Can you please show the full code?

Here is full code in node-red and screenshot. If I just hardcode the entity_id, it worked fine. but I’d like to get the entity_id by using Mustache templates.

[{"id":"653c65a9.7e5d9c","type":"server-state-changed","z":"845016a6.b38828","name":"wyze garage2 open?","server":"e8b4e59e.644ec8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.wyzesense_xxxx","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":170,"y":1420,"wires":[["f8587ea5.02461"],[]]},{"id":"f8587ea5.02461","type":"ha-wait-until","z":"845016a6.b38828","name":"wait 10m","server":"e8b4e59e.644ec8","outputs":2,"entityId":"{{data.entity_id}}","property":"state","comparator":"is_not","value":"on","valueType":"str","timeout":"10","timeoutUnits":"minutes","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":360,"y":1420,"wires":[[],[]]},{"id":"e8b4e59e.644ec8","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Screen Shot 2020-03-13 at 3.13.18 PM

Oh I realized now that this is node-red, I don’t know anyrhing about node red, sorry. But I’ll move the thread to the appropriate category.

2 Likes

use this:

or you can also use {{data.entity_id}}

1 Like

Thanks for your response.

I’ve tried both {{data.entity_id}} (which was what I used in my previous post) and {{topic}}, neither works. When I put the actual entity_id, it works fine.

Not sure where broke…

You can check with a debug node (set to show the complete message object) which message will actually show you the entity id. Try that first :slight_smile: Then simply copy the path and set it in brackets. Works fine for me. If that still doesn’t work, maybe the error is of a different kind.

1 Like

Yes, I used debug node complete message to find the msg, which is in the first post.

Hi Henry - had the same issue with the “wait until” node. I think there must be something wrong with that specific node, because if you use it for a call service node, the template works fine. Let me know if you had any luck

No it doesn’t work for me.

Have a look at Wait until strange behaviour
If you put the template in a change node before the wait until you might be more successful.

GV

2 Likes