Help adding time to an input_number

Can a JSON aficionado help me here. I’m almost there, just horrible with JSON.

I have the current amount of seconds the fridge has been opened being sent to the ‘set input_number’ node in the msg.duration field. How do I have that valuer be ADDED to the current number, and not just replaced.

So if input_number.fridge is currently at 6, and msg.duration = 3, I want the new value of input.nnumber_fridge to be 9

[{"id":"58112c045cb6f52a","type":"tab","label":"Flow 5","disabled":false,"info":"","env":[]},{"id":"e2c73e76a96eb792","type":"inject","z":"58112c045cb6f52a","name":"Fridge opened","props":[{"p":"command","v":"start","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":179,"y":162,"wires":[["603a73482f847ecc"]]},{"id":"f281b49569119026","type":"inject","z":"58112c045cb6f52a","name":"Fridge closed","props":[{"p":"command","v":"stop","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":188,"y":243,"wires":[["603a73482f847ecc","9c101a4ce20cc5f8"]]},{"id":"9c101a4ce20cc5f8","type":"change","z":"58112c045cb6f52a","name":"Status","rules":[{"t":"set","p":"command","pt":"msg","to":"status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":186,"y":297,"wires":[["603a73482f847ecc","383b6551d1d2c17c"]]},{"id":"383b6551d1d2c17c","type":"change","z":"58112c045cb6f52a","name":"Reset","rules":[{"t":"set","p":"command","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":176,"y":351,"wires":[["603a73482f847ecc"]]},{"id":"603a73482f847ecc","type":"hourglass","z":"58112c045cb6f52a","name":"Counter","persistId":"","humanizeLocale":"","x":501,"y":252,"wires":[["fc2f75e972497e54"]]},{"id":"fc2f75e972497e54","type":"change","z":"58112c045cb6f52a","name":"Convert milliseconds to seconds, set in msg.duration","rules":[{"t":"set","p":"duration","pt":"msg","to":"msg.elapsed.millis/1000","tot":"jsonata"},{"t":"set","p":"duration","pt":"msg","to":"$round(duration, 0)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":841,"y":252,"wires":[["aa4ab91ef18eb897"]]},{"id":"aa4ab91ef18eb897","type":"api-call-service","z":"58112c045cb6f52a","name":"Set input_number","server":"ab3e2c53.e3491","version":3,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.fridge","data":"{\"value\":\"{{duration}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1216,"y":252,"wires":[[]]},{"id":"ab3e2c53.e3491","type":"server","name":"AvilaSmartHome","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Should be able to go directly from the hourglass node to a call-service node

image

[{"id":"9b02d0ff740cd7b7","type":"inject","z":"58112c045cb6f52a","name":"3198","props":[{"p":"elapsed","v":"{    \"millis\": 3198}","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":544,"wires":[["7daff172ee971f13"]]},{"id":"1b5a73bd199b836b","type":"inject","z":"58112c045cb6f52a","name":"3898","props":[{"p":"elapsed","v":" {     \"millis\": 3898 }","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":576,"wires":[["7daff172ee971f13"]]},{"id":"63506207dbb4099b","type":"inject","z":"58112c045cb6f52a","name":"0","props":[{"p":"elapsed","v":"{     \"millis\": 0}","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":608,"wires":[["7daff172ee971f13"]]},{"id":"7daff172ee971f13","type":"api-call-service","z":"58112c045cb6f52a","name":"Set input_number","server":"","version":3,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.fridge","data":"{\"value\": $round(elapsed.millis/1000,0)}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":442,"y":544,"wires":[[]]}]

@Kermit

How do I add the new value to whatever the input_number is currently set to? (I want to keep a running tally of the time in seconds, that the fridge is opened. So everytime the fridge opens, counter starts and once its closed it triggers hourglass node to send current time it was opened and that gets added to the input_number I found posts such as the one below, but when i try to convert that to JSON and add it into data field, I get errors.

I was thinking rather than the +50, I could put int {{msg.duration}}

{"value": $number($entities("input_number.current").state) + $round(elapsed.millis/1000,0)
1 Like

SaWeet! Thank you!

@Kermit

Is there anyway to remove the decimal point? I did some reading and apparently even though my step value is 1, a decimal point is still there and that normal, per HA developers.
image

Reading other posts, I have to do something like this…

Does that make sense to you?

Heres my current flow, incorporating all your suggestions so far.

[{"id":"a12daa4e9f01286e","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"0e4d959ded816e35","type":"inject","z":"a12daa4e9f01286e","name":"Fridge opened","props":[{"p":"command","v":"start","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":260,"y":144,"wires":[["e43dd979e980386a"]]},{"id":"c9da5284ce73ca27","type":"inject","z":"a12daa4e9f01286e","name":"Fridge closed","props":[{"p":"command","v":"stop","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":260,"y":189,"wires":[["e43dd979e980386a","b781d10e6c809730"]]},{"id":"b781d10e6c809730","type":"change","z":"a12daa4e9f01286e","name":"Status","rules":[{"t":"set","p":"command","pt":"msg","to":"status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":258,"y":243,"wires":[["e43dd979e980386a","89c0c0ad532166ef"]]},{"id":"89c0c0ad532166ef","type":"change","z":"a12daa4e9f01286e","name":"Reset","rules":[{"t":"set","p":"command","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":248,"y":297,"wires":[["e43dd979e980386a"]]},{"id":"e43dd979e980386a","type":"hourglass","z":"a12daa4e9f01286e","name":"Counter","persistId":"","humanizeLocale":"","x":573,"y":198,"wires":[["de5f8df4702e7e40"]]},{"id":"de5f8df4702e7e40","type":"api-call-service","z":"a12daa4e9f01286e","name":"Set input_number","server":"ab3e2c53.e3491","version":3,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.fridge","data":"{\"value\": $number($entities(\"input_number.fridge\").state) + $round(elapsed.millis/1000,0)}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":793,"y":198,"wires":[[]]},{"id":"ab3e2c53.e3491","type":"server","name":"AvilaSmartHome","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

You could use the entity node and create a sensor then not have to deal with input_number

Or input_text as if that’s more comfortable for you.

I ended up sticking with input_number and the decimals actually cause once I started thinking about it more, I’m gonna want to keep the readout in hours (cause 1846486 seconds really doesnt lend much insight at a quick glance).

And I need decimals because the fridge/freezer, for example, we probably average about a 20 second open. So I’ll need 3 digits to the right or else 10 seconds will never round to anything in hours.

Thanks for your help Kermit. For some reason, I cant mark a “solution” to the post though.

image

I’m not sure a float is much useful either. But sure…

I would probably go for a formatted timevalue

[{"id":"f91c0961d1a8d7db","type":"inject","z":"14ca354715bc92f3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1846486","payloadType":"num","x":220,"y":500,"wires":[["bc9264e098d3b6e2"]]},{"id":"bc9264e098d3b6e2","type":"moment","z":"14ca354715bc92f3","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Brussels","adjAmount":0,"adjType":"days","adjDir":"add","format":"HH:MM:SS","locale":"C","output":"","outputType":"msg","outTz":"Europe/Brussels","x":410,"y":500,"wires":[["ed0a70bcd258ea58"]]},{"id":"ed0a70bcd258ea58","type":"debug","z":"14ca354715bc92f3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":500,"wires":[]}]

But that means either a sensor or a input_text.

There can’t possibly be a solution in Node red, can there…
It’s disabled by some reason… :man_shrugging:

I made a feature request