Dashboard time picker send payload after button is pressed

Hi,

I am trying to create with dashboard functions a "week timer" that starts an internet radio stream on a google home device if the selected time is true

image

But I already get stuck with the time picker and SET button.
When I place them like this

image

The time picker sends an integer of the selected time but when I place a Button node in between, the msg.payload is a string called: 6d42b56e4b831218

How do you pass the integer value through the Button node?

After timepicker, use a change node to move it to msg.topic. Then in button set topic to msg.topic. Then after use another change node to move msg.topic back to msg.payload, or were ever you may need it.

Or store the value in context then in the button you can select from flow or global context.

Seem crazy you can no feed in a msg to the button payload.

Okay I have set everything as you said, but the the result is "undefined"

But your'e right, in the end I want to store the time (as an integer or as a time format?) in a global context because the chosen time should stay in the time picker until it is changed (even when my pi is rebooted)

[{"id":"b34ef5deb0d18471","type":"ui_text_input","z":"e8cdc00d.87099","name":"Monday Time Input","label":"","tooltip":"","group":"da420f01.d894","order":2,"width":"3","height":"1","passthru":true,"mode":"time","delay":"0","topic":"monday_time","sendOnBlur":true,"className":"","topicType":"str","x":210,"y":140,"wires":[["38b1310a96f5ef43"]]},{"id":"565295d90ae4291e","type":"debug","z":"e8cdc00d.87099","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1230,"y":140,"wires":[]},{"id":"6d42b56e4b831218","type":"ui_button","z":"e8cdc00d.87099","name":"Button Set","group":"da420f01.d894","order":3,"width":"1","height":"1","passthru":true,"label":"Set","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":770,"y":140,"wires":[["0a1c71ea769dc723"]]},{"id":"38b1310a96f5ef43","type":"change","z":"e8cdc00d.87099","name":"Move msg.monday to msg.topic","rules":[{"t":"move","p":"monday_time","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":140,"wires":[["6d42b56e4b831218"]]},{"id":"0a1c71ea769dc723","type":"change","z":"e8cdc00d.87099","name":"Move msg.topic to msg.payload","rules":[{"t":"move","p":"topic","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":140,"wires":[["565295d90ae4291e"]]},{"id":"da420f01.d894","type":"ui_group","name":"Week Timer","tab":"89465ae5.96ed08","order":1,"disp":true,"width":"6","collapse":true},{"id":"89465ae5.96ed08","type":"ui_tab","name":"Wekker Faye-Linn","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

some thing like this , you will need to set topic to monday_time after the button

[{"id":"b34ef5deb0d18471","type":"ui_text_input","z":"bf9e1e33.030598","name":"Monday Time Input","label":"","tooltip":"","group":"da420f01.d894","order":2,"width":"3","height":"1","passthru":true,"mode":"time","delay":"0","topic":"monday_time","sendOnBlur":true,"className":"","topicType":"str","x":230,"y":1660,"wires":[["38b1310a96f5ef43"]]},{"id":"38b1310a96f5ef43","type":"change","z":"bf9e1e33.030598","name":"Move msg.monday to msg.topic","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1660,"wires":[["6d42b56e4b831218"]]},{"id":"6d42b56e4b831218","type":"ui_button","z":"bf9e1e33.030598","name":"Button Set","group":"da420f01.d894","order":3,"width":"1","height":"1","passthru":false,"label":"Set","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"1","payloadType":"str","topic":"topic","topicType":"msg","x":790,"y":1660,"wires":[["0a1c71ea769dc723"]]},{"id":"0a1c71ea769dc723","type":"change","z":"bf9e1e33.030598","name":"Move msg.topic to msg.payload","rules":[{"t":"move","p":"topic","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"monday_time","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":1660,"wires":[["565295d90ae4291e"]]},{"id":"565295d90ae4291e","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1250,"y":1660,"wires":[]},{"id":"da420f01.d894","type":"ui_group","name":"Week Timer","tab":"89465ae5.96ed08","order":1,"disp":true,"width":"6","collapse":true},{"id":"89465ae5.96ed08","type":"ui_tab","name":"Wekker Faye-Linn","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

or
saving to context

[{"id":"b34ef5deb0d18471","type":"ui_text_input","z":"bf9e1e33.030598","name":"Monday Time Input","label":"","tooltip":"","group":"da420f01.d894","order":2,"width":"3","height":"1","passthru":true,"mode":"time","delay":"0","topic":"monday_time","sendOnBlur":true,"className":"","topicType":"str","x":190,"y":1740,"wires":[["38b1310a96f5ef43"]]},{"id":"38b1310a96f5ef43","type":"change","z":"bf9e1e33.030598","name":"Move msg.monday to msg.topic","rules":[{"t":"move","p":"payload","pt":"msg","to":"monday_time","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":1740,"wires":[[]]},{"id":"6d42b56e4b831218","type":"ui_button","z":"bf9e1e33.030598","name":"Button Set","group":"da420f01.d894","order":3,"width":"1","height":"1","passthru":true,"label":"Set","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"monday_time","payloadType":"flow","topic":"monday_time","topicType":"str","x":660,"y":1800,"wires":[["565295d90ae4291e"]]},{"id":"565295d90ae4291e","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":1800,"wires":[]},{"id":"da420f01.d894","type":"ui_group","name":"Week Timer","tab":"89465ae5.96ed08","order":1,"disp":true,"width":"6","collapse":true},{"id":"89465ae5.96ed08","type":"ui_tab","name":"Wekker Faye-Linn","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Thanx @E1cid this is working!

Why doesn't it matter in the "saving to context" example, whether the switch node is connected to the button node or not (newbie here)?
Is this because the message is moved to flow.monday_time?

Is this context value also restored (in the time picker) after Node-Red is restarted?
My raspberry always reboots once a week.

No wire is required as the value is stored to context, similar to a db you can then access that value from anywhere if global, and anywhere on tab if flow.

You need to add a setting to you settings file if you want the value to be persistent over restarts
https://nodered.org/docs/user-guide/context#saving-context-data-to-the-file-system

@E1cid
Thanx i'll dig into it

Okay my current settings.js file the contextStorage was set like this, but when I restart Node-Red the context value was reset

contextStorage: {
   default: {
       module: "localfilesystem"
   }
}

When changed it to below, the site (http://192.168.1.51:1880/) won't start...why is that?
Or I need to modify settings.js (on a pi with buster) as Root user instead of Pi user?

contextStorage: {
	   default: "memoryOnly",
	   memoryOnly: { module: 'memory' },
	   file: { module: 'localfilesystem' }
	}

You probably created a syntax error, maybe missing a comma. Post a larger section so we can see what you did. Did you make a copy before you tried to make changes?

Nope I changed the settings.js with the nano editor (I re-typed it after you said it may be a typing error) only the part like the picture...and restarted node-red....still no connection

When I change it back to the old, Node-Red starts normally

What I do notice is that with the old setting Node-Red restarts within 1 sec
With the new setting it takes around 10-20 seconds....like it is trying to access a location which is not accessible

The old is commented out so is unseen, remove the // from infront of the five lines, and delete your new. Or add a comma to the end of your new lines.

P.S. Always post code as text, and between triple backticks. use the </> icon

It was the missing comma at the end of the new code....now it is working, thanx.
This comma is not in the node-red example link you posted

@E1cid

Okay so I store the time integer to context [file] with the Change Node and retrieve the context [file] in the payload of the Button Node like the example below

But when I re-deploy the flow or restart node-red, the Time Picker does not restore the time.
How do you restore monday_time into the Time Picker after a reboot/restart?

[{"id":"b34ef5deb0d18471","type":"ui_text_input","z":"e8cdc00d.87099","name":"Monday Time Input","label":"","tooltip":"","group":"da420f01.d894","order":2,"width":"3","height":"1","passthru":true,"mode":"time","delay":"0","topic":"monday_time","sendOnBlur":true,"className":"","topicType":"str","x":210,"y":140,"wires":[["38b1310a96f5ef43"]]},{"id":"565295d90ae4291e","type":"debug","z":"e8cdc00d.87099","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":140,"wires":[]},{"id":"6d42b56e4b831218","type":"ui_button","z":"e8cdc00d.87099","name":"Button Set","group":"da420f01.d894","order":3,"width":"1","height":"1","passthru":true,"label":"Set","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"#:(file)::monday_time","payloadType":"flow","topic":"monday_time","topicType":"str","x":830,"y":140,"wires":[["565295d90ae4291e"]]},{"id":"38b1310a96f5ef43","type":"change","z":"e8cdc00d.87099","name":"Move Monday Time Integer to Context [File]","rules":[{"t":"move","p":"payload","pt":"msg","to":"#:(file)::monday_time","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":140,"wires":[[]]},{"id":"da420f01.d894","type":"ui_group","name":"Week Timer","tab":"89465ae5.96ed08","order":1,"disp":true,"width":"6","collapse":true},{"id":"89465ae5.96ed08","type":"ui_tab","name":"Wekker Faye-Linn","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Where you are saving the value to context you have not selected the File context using the dropdown at the right hand side.
You can check using the context viewer in the right hand pane that you are saving it to the right place.

Not sure what you mean, but this flow seems to work now (also after reboot)

[{"id":"b34ef5deb0d18471","type":"ui_text_input","z":"e8cdc00d.87099","name":"Monday Time Input","label":"","tooltip":"","group":"da420f01.d894","order":2,"width":"3","height":"1","passthru":true,"mode":"time","delay":"0","topic":"monday","sendOnBlur":true,"className":"","topicType":"str","x":650,"y":120,"wires":[["38b1310a96f5ef43"]]},{"id":"565295d90ae4291e","type":"debug","z":"e8cdc00d.87099","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1430,"y":120,"wires":[]},{"id":"6d42b56e4b831218","type":"ui_button","z":"e8cdc00d.87099","name":"Button Set","group":"da420f01.d894","order":3,"width":"1","height":"1","passthru":true,"label":"Set","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"#:(file)::monday_time","payloadType":"flow","topic":"monday","topicType":"str","x":1230,"y":120,"wires":[["565295d90ae4291e"]]},{"id":"38b1310a96f5ef43","type":"change","z":"e8cdc00d.87099","name":"Save monday_time value to Context [File]","rules":[{"t":"move","p":"payload","pt":"msg","to":"#:(file)::monday_time","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":120,"wires":[[]]},{"id":"4df8851ed43a7ed5","type":"inject","z":"e8cdc00d.87099","name":"Inject After Reboot","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"monday","payloadType":"date","x":170,"y":120,"wires":[["c6b2a68dd0b721bb"]]},{"id":"c6b2a68dd0b721bb","type":"change","z":"e8cdc00d.87099","name":"Restore monday_time","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(file)::monday_time","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":120,"wires":[["b34ef5deb0d18471"]]},{"id":"da420f01.d894","type":"ui_group","name":"Week Timer","tab":"89465ae5.96ed08","order":1,"disp":true,"width":"6","collapse":true},{"id":"89465ae5.96ed08","type":"ui_tab","name":"Wekker Faye-Linn","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

The Context monday_time is stored to file which I already have done I thought?

image

Add an inject node, to fire once after 0.1seconds. Sending the payload as flow.monday_time.

[{"id":"d08cf790.e33588","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"monday_time","payloadType":"flow","x":140,"y":180,"wires":[["b34ef5deb0d18471"]]},{"id":"b34ef5deb0d18471","type":"ui_text_input","z":"bf9e1e33.030598","name":"Monday Time Input","label":"","tooltip":"","group":"da420f01.d894","order":2,"width":"3","height":"1","passthru":false,"mode":"time","delay":"0","topic":"monday_time","sendOnBlur":true,"className":"","topicType":"str","x":210,"y":80,"wires":[["38b1310a96f5ef43"]]},{"id":"38b1310a96f5ef43","type":"change","z":"bf9e1e33.030598","name":"Move Monday Time Integer to Context [File]","rules":[{"t":"move","p":"payload","pt":"msg","to":"#:(file)::monday_time","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":120,"wires":[[]]},{"id":"da420f01.d894","type":"ui_group","name":"Week Timer","tab":"89465ae5.96ed08","order":1,"disp":true,"width":"6","collapse":true},{"id":"89465ae5.96ed08","type":"ui_tab","name":"Wekker Faye-Linn","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

I meant here, I thought you were saving it to memory context not file, but actually I see it is an error on my part. I thought that with the theme I am using that memory is selected, but actually you were correct, it is File.
image

When the dashboard runs for the first time, the injector is not able to load the flow.monday_time data because it is not defined yet. How do I solve that? Or doesn't it matter?

If you have saved the monday_time to file context, then it should be defined. In the change node where you save to flow, have you selected file or memory ( As in Dave's image above). In the settings.js you set memory as default. So if you do not select a context memory storage it would default to memory, and not be persistent over restarts.