Trigger.entity_id YAML automation to node red NEWBIE

Hi,

I’m 100% new to Node Red and barely using YAML. I want to translate the following automation to Node Red. I’ve been googling but the little information I found is too cryptic for me, a step by step tutorial will be very appreciated, I have almost zero knowledge. I’ve just made my first flow but nothing more. Many thanks in advanced.

Automation:

  trigger:
  - platform: state
    entity_id:
      - light.number_1
      - light.number_2
      - light.number_3
      - light.number_4
    to: 'off'
  action:
  - service: lifx.set_state
    data_template:
      color_name: "{{ ['color1', 'color2', 'color3', 'color4', 'color5'] | random }}"
      entity_id: "{{ trigger.entity_id}}"
1 Like

or at least with some detail please :), not need for step by step, some clue

[{"id":"b177af87.768ed","type":"server-state-changed","z":"56b1c979.b2c618","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.number_1, light.number_2, light.number_3, light.number_4","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":378,"y":1456,"wires":[["15688cdf.e89a73"]]},{"id":"15688cdf.e89a73","type":"api-call-service","z":"56b1c979.b2c618","name":"","version":1,"debugenabled":false,"service_domain":"lifx","service":"set_state","entityId":"{{topic}}","data":"{\"color_name\":\"{{ ['color1', 'color2', 'color3', 'color4', 'color5'] | random }}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":778,"y":1456,"wires":[[]]}]

could you please be so kind as to share the content of those two nodes? I’m new here and the code you pasted underneath means nothing to me. I’ve tried any combination and I can’t get it to work.

The state change node works, my problem is setting the entity_id part. I put this in te Data section of the service node:

{"color_name": "red", "entity_id": "{{trigger.entity_id}}" }

and I left the entity_id above blank. It yields an API error, I guess it’s a syntax issue.

https://nodered.org/docs/user-guide/editor/workspace/import-export

1 Like

{{topic}} instead of {{trigger.entity_id}} then, thanks

and going a little bit further, I want alexa to send a different message depending on the trigger, how could I do that, I tried the following:

{"message":"{% if {{topic}} == light.q_cocina %}hola{% else %}adios{% endif %}","data":{"type":"tts"},"target":"{{service}}"}

thanks in advanced

a switch node can help you there.

1 Like

thanks mate, that did it

hey guys, I’m pushing it a bit further with the trigger.entity_id. I’m trying to translate this to Node Red:

  trigger:
  - platform: state
    entity_id: sensor.aemet_current_temp
  condition:
    condition: and
        conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state|float < states.climate.calefaccion.attributes.current_temperature|float + 1 }}"
        - condition: template
          value_template: "{{ states.weather.aemet.attributes.forecast[0].temperature|float > 23 }}"
        - condition: time
          after: '20:01:00'
          before: '23:59:59'

So far I’ve got the following, but I’ struggling to get the “{{ trigger.to_state.state|float < states.climate.calefaccion.attributes.current_temperature|float + 1 }}” in

[{"id":"19a3656f.745ccb","type":"trigger-state","z":"ea121e86.45601","name":"trigger","server":"9405c3fe.d0a6c","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.aemet_current_temp","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"ohqevf59cjf","targetType":"entity_id","targetValue":"weather.aemet","propertyType":"property","propertyValue":"attributes.forecast.0.temperature","comparatorType":">","comparatorValueDatatype":"num","comparatorValue":"23"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"num","x":180,"y":240,"wires":[["9bafb8c5.423568"],[]]},{"id":"9bafb8c5.423568","type":"time-range-switch","z":"ea121e86.45601","name":"time condition","lat":"","lon":"","startTime":"20:01:00","endTime":"23:59:59","startOffset":0,"endOffset":0,"x":360,"y":240,"wires":[[],[]]},{"id":"9405c3fe.d0a6c","type":"server","z":"","name":"Home Assistant","addon":true}]

thanks in advanced