Home Assistant Value Templates in Node Red

Hey all,

I have a yaml home assistant automation that I want to convert to NR. But I’m unsure how to have NR do the value template checks?

Can a sequence be a named entity as it were, that can be referenced by other sequences?

This is my .yaml

alias: 'Motion: Morning Bathroom'
description: ''
trigger:
  - type: motion
    platform: device
    device_id: 9c689b630452da3f476181b33d1fa1b4
    entity_id: binary_sensor.bathroom_motion_sensor_motion
    domain: binary_sensor
condition:
  - condition: time
    after: '07:00'
    before: '11:00'
  - condition: template
    value_template: >-
      {{ ((as_timestamp(now()) | float) -
      (as_timestamp(state_attr('automation.motion_morning','last_triggered')) |
      default(0) | float)) > 36000.0 }}
  - condition: template
    value_template: >-
      {{as_timestamp(now()) -
      as_timestamp(states.automation.motion_morning_kitchen.attributes.last_triggered)|
      int >= 14400}}
action:
  - service: script.alexa_flash_briefing_volume
    data: {}
  - service: script.good_morning_bathroom
    data: {}
mode: single

you mean flow called from other flows? Yes it can be achieved in at least 2 ways.
But likely not by name. Just by putting (sub)flow onto main flow.

NR has template node too. But it has other tools incl JavaScript or conditional nodes. I suggest to forget about “programming” with use of templates.

Thanks for replying to this :slight_smile:

So as part of that automation, I have a value template that runs to see A if its been run in the last 4 hours, B if the other version (for the Kitchen) of the automation has been run. Hence the question, can I reference to see if other sequences have been run and then not run it if they have.

But Im thinking about it wrong?

Can you point me to any examples of what Im trying to do… Would really appreciate it :slight_smile:

Thanks again for having a look.

Until somebody else offers you a more beautiful solution, this will do it. It mimics your conditional section from you Yaml code.

[{"id":"936adf70.e56d9","type":"time-range-switch","z":"10e86c3d.c28d14","name":"","lat":"","lon":"","startTime":"07:00","endTime":"11:00","startOffset":0,"endOffset":0,"x":280,"y":140,"wires":[["2f08fbd7.278124"],[]]},{"id":"b07f8abc.d28c38","type":"inject","z":"10e86c3d.c28d14","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":140,"wires":[["936adf70.e56d9"]]},{"id":"2f08fbd7.278124","type":"api-render-template","z":"10e86c3d.c28d14","name":"Template one","server":"9405c3fe.d0a6c","template":"{{ ((as_timestamp(now()) | float) -\n      (as_timestamp(state_attr('automation.motion_morning','last_triggered')) |\n      default(0) | float)) > 36000.0 }}","resultsLocation":"templateOne","resultsLocationType":"msg","templateLocation":"","templateLocationType":"none","x":470,"y":140,"wires":[["3a2c0b3b.df0dd4"]]},{"id":"3a2c0b3b.df0dd4","type":"switch","z":"10e86c3d.c28d14","name":"is True?","property":"templateOne","propertyType":"msg","rules":[{"t":"eq","v":"True","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":140,"wires":[["7f074701.e4ed18"]]},{"id":"7f074701.e4ed18","type":"api-render-template","z":"10e86c3d.c28d14","name":"Template two","server":"9405c3fe.d0a6c","template":"{{as_timestamp(now()) - \n      as_timestamp(states.automation.motion_morning_kitchen.attributes.last_triggered)|\n      int >= 14400}}","resultsLocation":"templateTwo","resultsLocationType":"msg","templateLocation":"","templateLocationType":"none","x":790,"y":140,"wires":[["4da4a4d0.b75f8c"]]},{"id":"4da4a4d0.b75f8c","type":"switch","z":"10e86c3d.c28d14","name":"is True?","property":"templateTwo","propertyType":"msg","rules":[{"t":"eq","v":"True","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":960,"y":140,"wires":[["29d9ac07.d94314"]]},{"id":"29d9ac07.d94314","type":"debug","z":"10e86c3d.c28d14","name":"Then do","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":140,"wires":[]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]
1 Like

regarding this, I assume that you want to move your automation.motion_morning and your automation.motion_morning_kitchen to Node Red and you dunno how you will be able to know their last_triggered values?

There are a few values to work with: last_updated, last_changed and timeSinceChangedMs

Thanks so much for helping me out with this, appreciate it.

I still have not had a chance to test this yet, but just thought its better to give some update then none at all LOL

I know it annoys the hell out of me when your trying to help someone and they don’t reply :slight_smile:

So thank you, I will get to this as soon as I’ve squashed the bigger bugs… Well I say bugs, I mean my crappy automation skills HAHA

1 Like