Turning a yaml automation to node red

Hello all!

I’ve decided to ditch the YAML code and go for the Node-Red way!

A lot of things work, but there is this one automation I can’t make work properly in Node-Red.

It works in perfectly in YAML. So when it’s 8:32 and none of our phones are charging, the shutters (Rolluiken :wink: ) can go up. If one phone is charging, they can’t go up.

- alias: rolluiken boven omhoog ochtend
  description: ""
  trigger:
    - platform: time
      at: 08:32:01
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.motorola_one_action_is_aan_het_opladen
        state: "off"
      - condition: state
        entity_id: binary_sensor.sm_a405fn_is_aan_het_opladen
        state: "off"
  action:
    - service: nodered.trigger
      data:
        entity_id: switch.boven_alles_op

This is the flow in Node-Red:

[{"id":"646820f5.f1109","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"ca8e5f0f.91ff6","type":"api-call-service","z":"646820f5.f1109","name":"Boven omhoog","server":"561508bb.cf72f8","version":1,"debugenabled":false,"service_domain":"nodered","service":"trigger","entityId":"switch.boven_alles_op","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":740,"y":160,"wires":[[]]},{"id":"95e80375.8e44e","type":"and-gate","z":"646820f5.f1109","name":"","rules":[{"t":"eq","v":"off","vt":"str","propertyType":"msg","property":"payload","topic":"binary_sensor.motorola_one_action_is_aan_het_opladen"},{"t":"eq","v":"off","vt":"str","propertyType":"msg","property":"payload","topic":"binary_sensor.sm_a405fn_is_aan_het_opladen"}],"outputTopic":"","gateType":"and","emitOnlyIfTrue":true,"x":260,"y":180,"wires":[["cdf2d907.c95038"]]},{"id":"e8933209.f2c62","type":"server-state-changed","z":"646820f5.f1109","name":"gsm stef","server":"561508bb.cf72f8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.motorola_one_action_is_aan_het_opladen","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":100,"y":140,"wires":[["95e80375.8e44e"]]},{"id":"a6aa6db7.fc1a2","type":"server-state-changed","z":"646820f5.f1109","name":"gsm bieke","server":"561508bb.cf72f8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.sm_a405fn_is_aan_het_opladen","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":100,"y":220,"wires":[["95e80375.8e44e"]]},{"id":"cdf2d907.c95038","type":"time-range-switch","z":"646820f5.f1109","name":"","lat":"50.90289","lon":"2.92136","startTime":"08:30","endTime":"08:31","startOffset":0,"endOffset":0,"x":470,"y":180,"wires":[["ca8e5f0f.91ff6"],[]]},{"id":"561508bb.cf72f8","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

It only triggers when we disconnect the phone in the specfic time range… But it has to do this as well when none of our phones are charging.

Any tips or tricks or help?

I can’t import your sequence, I’m missing the and-gate.
I’m fairly sure that is not needed.

What is the difference between disconnect and when none of our phones are charging?

I guess he means that he has to disconnect a phone to trigger it so when it is 8:30 and no phone is charging it doesn’t trigger.

I also couldn’t import it, but maybe something like this could work if I understood you correctly:

[{"id":"5bd57e45.3dc85","type":"server-state-changed","z":"cc639dbb.119d5","name":"","server":"44b2605f.5d41","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"yourTimeEntityHere","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"8:30","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":200,"y":1340,"wires":[["b837e09c.2f4cc"],[]]},{"id":"b837e09c.2f4cc","type":"ha-wait-until","z":"cc639dbb.119d5","name":"","server":"44b2605f.5d41","outputs":1,"entityId":"binary_sensor.motorola_one_action_is_aan_het_opladen","entityIdFilterType":"exact","property":"state","comparator":"is","value":"off","valueType":"str","timeout":0,"timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":490,"y":1340,"wires":[["db65335e.3ff6f"]]},{"id":"db65335e.3ff6f","type":"ha-wait-until","z":"cc639dbb.119d5","name":"","server":"44b2605f.5d41","outputs":1,"entityId":"binary_sensor.sm_a405fn_is_aan_het_opladen","entityIdFilterType":"exact","property":"state","comparator":"is","value":"off","valueType":"str","timeout":0,"timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":640,"y":1340,"wires":[["6c5aa87.d32db58"]]},{"id":"6c5aa87.d32db58","type":"api-call-service","z":"cc639dbb.119d5","name":"","server":"44b2605f.5d41","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":860,"y":1340,"wires":[[]]},{"id":"2ba63aa7.18ab76","type":"comment","z":"cc639dbb.119d5","name":"Your action (switch.boven_alles_op)","info":"","x":950,"y":1300,"wires":[]},{"id":"77627336.1fc83c","type":"comment","z":"cc639dbb.119d5","name":"Trigger: time is 8:30","info":"","x":160,"y":1280,"wires":[]},{"id":"44b2605f.5d41","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"on","connectionDelay":false,"cacheJson":false}]

So the use of this automation:

When it’s 8:30 the shutters (switch.boven alles op) should be executed, but if one of our phones (2 phones) are charging they shouldn’t go up. Even when they are unplugged after that time, they shouldn’t go up.

Like this?

[{"id":"5fe5629c.f1036c","type":"inject","z":"d9f7b25f.dfaab","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"31 08 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":360,"wires":[["9aeebd7e.2d73d"]]},{"id":"9aeebd7e.2d73d","type":"api-current-state","z":"d9f7b25f.dfaab","name":"Motorola one","server":"4bbca37b.1700ec","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.motorola_one_action_is_aan_het_opladen","state_type":"str","state_location":"motorola_one","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":490,"y":360,"wires":[["5429cb62.27cca4"]]},{"id":"7e7aff77.64096","type":"api-current-state","z":"d9f7b25f.dfaab","name":"sm a405","server":"4bbca37b.1700ec","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.sm_a405fn_is_aan_het_opladen","state_type":"str","state_location":"sm_a405","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":800,"y":360,"wires":[["1bc47cf3.5e71c3"]]},{"id":"5429cb62.27cca4","type":"switch","z":"d9f7b25f.dfaab","name":"","property":"motorola_one","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":650,"y":360,"wires":[["7e7aff77.64096"]]},{"id":"1bc47cf3.5e71c3","type":"switch","z":"d9f7b25f.dfaab","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"sm_a405","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":950,"y":360,"wires":[["679e8a8f.9be3e4"]]},{"id":"679e8a8f.9be3e4","type":"api-call-service","z":"d9f7b25f.dfaab","name":"","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.boven_alles_op","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1130,"y":360,"wires":[[]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

i guess the same but without switches:

[{"id":"5bd57e45.3dc85","type":"server-state-changed","z":"cc639dbb.119d5","name":"","server":"44b2605f.5d41","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"yourTimeEntityHere","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"8:30","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":200,"y":1340,"wires":[["96a31dfb.e220c"],[]]},{"id":"77627336.1fc83c","type":"comment","z":"cc639dbb.119d5","name":"Trigger: time is 8:30","info":"","x":160,"y":1280,"wires":[]},{"id":"6c5aa87.d32db58","type":"api-call-service","z":"cc639dbb.119d5","name":"","server":"44b2605f.5d41","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":990,"y":1400,"wires":[[]]},{"id":"2ba63aa7.18ab76","type":"comment","z":"cc639dbb.119d5","name":"Your action (switch.boven_alles_op)","info":"","x":1100,"y":1340,"wires":[]},{"id":"96a31dfb.e220c","type":"api-current-state","z":"cc639dbb.119d5","name":"","server":"44b2605f.5d41","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.motorola_one_action_is_aan_het_opladen","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":1340,"wires":[[],["b89eb274.96613"]]},{"id":"b89eb274.96613","type":"api-current-state","z":"cc639dbb.119d5","name":"","server":"44b2605f.5d41","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.sm_a405fn_is_aan_het_opladen","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":610,"y":1400,"wires":[[],["6c5aa87.d32db58"]]},{"id":"44b2605f.5d41","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"on","connectionDelay":false,"cacheJson":false}]
1 Like

This one works… Will it also work the other way round with the phones?

Do you mean an automation to get the shutters down? Or like in your flow that the phones are at the beginning?

Now the Motorola phone is the first phone and the SMA second one. Will it also work if the SMA phone is unplugged first?

You said it shouldn’t happen after that time.
At 8:30 the check is done, not before, not after. What phone is disconnected first is irrelevant.

Yes because it checks the current state of each phone.
The last node only gets triggered if both are unplugged

Edit: like @Hellis81 said it only checks once at 8:30 if one phone is still charging nothing will happen

1 Like

Thank you very much!

I tested it and it works!

Just a thought…
Isn’t it better to read the calendar and/or alarm time if you want the shutters to open than relying on a charging phone?

We use a normal ‘stupid’ alarm clock :wink: