How to trigger a flow in node-red from HA lovelace ui?

Hello Kermit,

Thank you for sharing.

I followed the instruction, and created a button. and I did triggered a flow in Node red from home assistant lovelace UI. However, the problem is:

a. when never I push the bottone for one time, the button node in node red will fire multiple events. do you know why?

b. even though I installed node red companion (from HACS), but did didn’t find the nodered.trigger service.

Could you please help to take a check?

[{"id":"ac7f510db8bb03d7","type":"subflow","name":"log","info":"","category":"","in":[{"x":140,"y":180,"wires":[{"id":"c45cdb23da2a1761"}]}],"out":[{"x":760,"y":180,"wires":[{"id":"c45cdb23da2a1761","port":0}]}],"env":[],"meta":{},"color":"#DDAA99","status":{"x":760,"y":320,"wires":[{"id":"a005a35b4ea9adf8","port":0}]}},{"id":"c45cdb23da2a1761","type":"function","z":"ac7f510db8bb03d7","name":"","func":"\n\nvar  timestamp = (new Date()).toLocaleDateString() + \" \" + (new Date()).toLocaleTimeString('en-GB');\n\nmsg.log_display = timestamp \n\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":180,"wires":[["a005a35b4ea9adf8"]]},{"id":"a005a35b4ea9adf8","type":"change","z":"ac7f510db8bb03d7","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"log_display","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":300,"wires":[[]]},{"id":"6d18db3950f0affc","type":"subflow:ac7f510db8bb03d7","z":"39db5f1eba3113f9","name":"","x":530,"y":2800,"wires":[["d5444067a512c856"]]},{"id":"d5444067a512c856","type":"debug","z":"39db5f1eba3113f9","name":"debug 101","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"data","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":2800,"wires":[]},{"id":"79db1c6c41dc9a88","type":"ha-button","z":"39db5f1eba3113f9","name":"prev_time_slot","version":0,"debugenabled":false,"outputs":1,"entityConfig":"a3ac758e091b0886","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":320,"y":2820,"wires":[["6d18db3950f0affc"]]},{"id":"a3ac758e091b0886","type":"ha-entity-config","server":"538475ac.a2270c","deviceConfig":"","name":"prev_time_slot","version":"6","entityType":"button","haConfig":[{"property":"name","value":"prev_time_slot"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"538475ac.a2270c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Show your work. Is this a physical button or a dashboard button? Show your code.

Hello Steven,

Thank you for reply.

I created the button in Node Red (with Node red companion). please refer the picture below.

But this issue does not happen every time. and Now I cannot repeat it… So, please forget it at the moment. and I’ll come here again when this issue happen again.

I also figured out a walk around solution as below:

[{"id":"75b4d23308f364b5","type":"trigger","z":"0266edf078264249","name":"1s","op1":"","op2":"","op1type":"pay","op2type":"nul","duration":"1","extend":false,"overrideDelay":true,"units":"s","reset":"STOP","bytopic":"all","topic":"topic","outputs":1,"x":730,"y":2180,"wires":[["ad8543e1f1c3d328","a323064091da025c"]]},{"id":"ad8543e1f1c3d328","type":"change","z":"0266edf078264249","name":"STOP","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":2080,"wires":[["75b4d23308f364b5"]]},{"id":"8ff0fc69b0ec8572","type":"ha-button","z":"0266edf078264249","name":"next_time_slot","version":0,"debugenabled":false,"outputs":1,"entityConfig":"2b9e0c24d4e7160a","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":480,"y":2180,"wires":[["75b4d23308f364b5"]]},{"id":"a323064091da025c","type":"debug","z":"0266edf078264249","name":"debug 110","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":2180,"wires":[]},{"id":"2b9e0c24d4e7160a","type":"ha-entity-config","server":"538475ac.a2270c","deviceConfig":"","name":"next_time_slot","version":"6","entityType":"button","haConfig":[{"property":"name","value":"next_time_slot"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"538475ac.a2270c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Screenshot 2023-01-29 at 14.43.11

Hello, what was the reason for this issue. I face the same behavior and I can’t find a solution. Thx!

To be honest, I don’t know.

The bug never happen again. I guess you could delete those buttons and recreate them again. Hopefully it will solve the problem.

Good luck.

Hello Everyone,

Everything just broke after working perfectly for months.

Now when I try these examples which used to work perfectly

I am now getting all sort of errors like:

“Failed to call service nodered.trigger. expected dict for dictionary value @ data[‘message’]. Got None”

or

“Failed to call service nodered.trigger. extra keys not allowed @ data[‘payload’].”

I’m trying to find what I need to do to update my lovelace buttons to work like they used to … any hints please?

Breaking change - https://github.com/zachowj/hass-node-red/releases/tag/v3.0.0
docs - https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/custom_integration/exposed-nodes.html#trigger-an-exposed-event-node-from-a-service-call-nodered-trigger

service_data:
  entitiy_id: switch.lovelace_button
  message:
    payload:
      test: 123
      abc: xyz

Kermit - you are the bloody best ! Thank you for the super fast response !

Just hitting one more problem

The YAML runs without errors and it is getting triggered on the node red flow.
However no payload gets transferred to the switch in node red. In my code below, [r 1 g] normally flows through to my switch on the node red flow. Is there something else wrong with my formatting ?

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: nodered.trigger
  target:
    entity_id: switch.nodered_33cd77ea3a94d1d7
  data:
    message:
      payload: r 1 g
icon: si:foxtel
hold_action:
  action: none
name: Blue

Then I tried it again using your example. HASS does some auto-editing to get the below output. Again, nothing gets sent through to the switch I created in Node-Red using the HACS Node Red companion.

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: nodered.trigger
  target:
    entity_id: switch.nodered_switch
  data:
    message:
      payload:
        test: 123
        abc: xyz
icon: si:foxtel
hold_action:
  action: none
name: Blue

This is the node red debug output showing it running but no payload coming through.

image

The screen below is the end result of what I used to get and now trying to get at the end of my nodered flow
image

Any help would be wonderful !

Solved it … it was my stupid mistake …

I needed to update the palette for the HASS Websocket in NR as well. Once updated the payload came thru.

I set out today to fix lovelace tap_ and hold_actions that I broke a while back when I converted some of my custom:button-cards to templates incorporating variables.The tap_action is handled by HA while the hold_action is handled by NR.

I got the tap_action working after some trial-and-error. The hold_action gave me the “extra keys” errors. I set out to figure its problem and came across your post. (Honestly, I didn’t read the breaking change; I just looked at your code example.) I changed my yaml to incorporate the message: section. I noticed, however, in NR, the function that the hold_action was feeding into looked like it was getting a msg.payload.payload (which the function did not like). Ultimately, I just had to change payload: to message: and everything worked from there.

  hold_action:
    action: call-service
    service: nodered.trigger
    service_data:
      entity_id: switch.nodered_all_lights_to_rgb
      message:
        color_name: '[[[ return variables.var_color_name ]]]'