[SOLVED] Sensor (Time remaining), Octoprint, Text to speech,

Hello in the forum,

have a question. I have an Octoprint “Sensor” which shows the time remaining until the end of the print in seconds. I would like to use Node-RED to convert the sensor data into minutes and hours and then send this via voice output.
So far, I can ask the time of the sensor via the “trigger state” function. Here a number is output in the debug. These would then have to be converted into minutes and hours and inserted into the text of the speech output.

Here is a screenshot and then the flow…

[{"id":"5c2d89d8.26eae8","type":"tab","label":"3D-Drucker Restzeit","disabled":false,"info":""},{"id":"f9d72e34.1e91f","type":"inject","z":"5c2d89d8.26eae8","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":200,"wires":[["a8f9d9de.077308"]]},{"id":"a8f9d9de.077308","type":"trigger-state","z":"5c2d89d8.26eae8","name":"","server":"a446b7a.18bf248","entityid":"sensor.anycubic_mega_s_time_remaining","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":470,"y":360,"wires":[["8ad2f3b8.6d86d","522d28e0.b9fa48"],[]]},{"id":"8ad2f3b8.6d86d","type":"debug","z":"5c2d89d8.26eae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":870,"y":340,"wires":[]},{"id":"522d28e0.b9fa48","type":"change","z":"5c2d89d8.26eae8","name":"Sprachausgabe","rules":[{"t":"set","p":"payload","pt":"msg","to":"Der Druck dauert noch .......","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":680,"wires":[["f30e2257.f01cb"]]},{"id":"f30e2257.f01cb","type":"cast-to-client","z":"5c2d89d8.26eae8","name":"Audioausgabe","url":"","contentType":"","message":"","language":"de","ip":"192.168.178.70","port":"","volume":"50","x":660,"y":680,"wires":[[]]},{"id":"b239de26.82ce9","type":"comment","z":"5c2d89d8.26eae8","name":"to Test","info":"","x":130,"y":160,"wires":[]},{"id":"bd30c7f8.5105a8","type":"comment","z":"5c2d89d8.26eae8","name":"Convert seconds to minutes and hours","info":"","x":590,"y":440,"wires":[]},{"id":"747504f7.83bffc","type":"comment","z":"5c2d89d8.26eae8","name":"Text for speech output","info":"","x":460,"y":520,"wires":[]},{"id":"a7792adc.d1a1a8","type":"comment","z":"5c2d89d8.26eae8","name":"to Test","info":"","x":890,"y":300,"wires":[]},{"id":"a446b7a.18bf248","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Maybe someone can help or has done something like this before. I’m grateful for any help

Greetings and thanks in advance

You could add checking hours/minutes/seconds if they’re equal to zero and not output them.

const [hours, minutes, seconds] = new Date(msg.payload * 1000).toISOString().substr(11, 8).split(":");

msg.payload = `${hours} hour, ${minutes} minutes and ${seconds} seconds`;

return msg;
1 Like

Thank you for your answer. I’ll try if I can do it the way I would like …

Yeah it worked, many thanks for the help …:+1::checkered_flag:

Can you post the working flow?

Hello El_Duderino.
I installed and set up the “nora” plugin in Node-RED, which I use to communicate with “Home Assistant” via the “Google Home”. I could have just posted the process here but I thought it might make more sense to create a small plan so that you can create the process yourself, which is positive for the learning success.

For field “A” I set up “nora”, this of course has to happen in “Google Home”.

For field “B”, the status of the 3D printer is queried. this is created via the Octoprint sensor in “Home Assistant”.

For field “C” the value is converted into hours, minutes and seconds. Here is the code for it:

const [hours, minutes, seconds] = new Date(msg.payload * 1000).toISOString().substr(11, 8).split(":");

msg.payload = `Der Druck dauert noch ${hours} Stunden, ${minutes} Minuten und ${seconds} Sekunden`;

return msg;

For field “D” the “Google Home” is activated and reads the created text of field “C”.

I hope you can do something with it.

Much success in implementing …

2 Likes