Translating Automation data template to Node Red

I have an automation with a template that looks like this:

  action:
  - data_template:
      entity_id: media_player.sonos_4
      message: Light level {{states.sensor.ihome_smartmonitor_a26825_light_level.state|round}}
        lux and humidity is {{states.sensor.ihome_smartmonitor_a26825_humidity.state|round}} percent.
    service: tts.google_translate_say

Is there an easy way to refer to entity values embedded in a message like this in Node Red? Or do I have to retrieve each value individually to a variable and then combine them into a message and then output the message as a bunch of separate steps?

You can give this a try. Personally I never used it like you intend to yet but would be interesting to simplify some flows:
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html

EDIT

Works fine. Here an example for my Alexa Voice Service Call:

{
    "title": "Home Assistant",
    "message": "{{entity.light.kitchen_top.attributes.friendly_name}}",
    "data": {
        "type": "announce",
        "method": "all"
    }
}
1 Like

Thank you, that was the hint I needed. Sometimes it’s very difficult to find a specific example with a search when you don’t know exactly what you’re looking for.

For me the message that works in Node Red is then:

{
    "message": "Light level {{entity.sensor.ihome_smartmonitor_a26825_light_level}} lux
     and humidity is {{entity.sensor.ihome_smartmonitor_a26825_humidity.state}} percent."
}

Just to add some keywords that search engines can index for those looking for similar information:

Node Red, embed Home Assistant entity attribute value, curly moustache brackets