Rounding an input number

How do I take this current logic which produces the following, and instead make it result in just 544.

{"value": $number($entities("input_number.linktap_main_spigot_volume_sunday").state) + msg.payload}

image

Here is the full flow, if it matters.

[{"id":"470c561b7b7c90d9","type":"tab","label":"Guest bedroom","disabled":false,"info":"","env":[]},{"id":"8ea970bbbb798e7b","type":"junction","z":"470c561b7b7c90d9","x":760,"y":165,"wires":[["4395e1fd43c7f741"]]},{"id":"a8437c2b9c0ea310","type":"comment","z":"470c561b7b7c90d9","name":"Transfer gallons used","info":"","x":145,"y":120,"wires":[]},{"id":"2274504370dda920","type":"simpletime","z":"470c561b7b7c90d9","name":"","mydate":true,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":false,"mytimes":false,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":350,"y":165,"wires":[["aff693757d16e3d2"]]},{"id":"806f9d3784ae163c","type":"switch","z":"470c561b7b7c90d9","name":"","property":"mydate","propertyType":"msg","rules":[{"t":"cont","v":"Mon","vt":"str"},{"t":"cont","v":"Tue","vt":"str"},{"t":"cont","v":"Wed","vt":"str"},{"t":"cont","v":"Thu","vt":"str"},{"t":"cont","v":"Fri","vt":"str"},{"t":"cont","v":"Sat","vt":"str"},{"t":"cont","v":"Sun","vt":"str"}],"checkall":"true","repair":false,"outputs":7,"x":685,"y":180,"wires":[["2072dab6b8dc7aae","8ea970bbbb798e7b"],["048d91b65470883b","8ea970bbbb798e7b"],["d0f0c716f7bd591e","8ea970bbbb798e7b"],["e1d53027d05a2c97","8ea970bbbb798e7b"],["048db3c93789a9da","8ea970bbbb798e7b"],["588cb41da5a52a7c","8ea970bbbb798e7b"],["1ac1bcda18b1ccee","8ea970bbbb798e7b"]]},{"id":"aff693757d16e3d2","type":"api-current-state","z":"470c561b7b7c90d9","name":"Get volume","server":"ab3e2c53.e3491","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.linktap_main_spigot_volume","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":525,"y":165,"wires":[["806f9d3784ae163c"]]},{"id":"2072dab6b8dc7aae","type":"api-call-service","z":"470c561b7b7c90d9","name":"Add to Monday","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.linktap_main_spigot_volume_monday"],"data":"{\"value\": $number($entities(\"input_number.linktap_main_spigot_volume_monday\").state) + msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":165,"wires":[[]]},{"id":"b4ea6ddb1ef23e3c","type":"server-state-changed","z":"470c561b7b7c90d9","name":"Linktap main spigot off","server":"ab3e2c53.e3491","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.linktap_main_spigot","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":165,"wires":[["2274504370dda920"],[]]},{"id":"048d91b65470883b","type":"api-call-service","z":"470c561b7b7c90d9","name":"Add to Tuesday","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.linktap_main_spigot_volume_tuesday"],"data":"{\"value\": $number($entities(\"input_number.linktap_main_spigot_volume_tuesday\").state) + msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":195,"wires":[[]]},{"id":"d0f0c716f7bd591e","type":"api-call-service","z":"470c561b7b7c90d9","name":"Add to Wednesday","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.linktap_main_spigot_volume_wednesday"],"data":"{\"value\": $number($entities(\"input_number.linktap_main_spigot_volume_wednesday\").state) + msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":225,"wires":[[]]},{"id":"e1d53027d05a2c97","type":"api-call-service","z":"470c561b7b7c90d9","name":"Add to Thursday","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.linktap_main_spigot_volume_thursday"],"data":"{\"value\": $number($entities(\"input_number.linktap_main_spigot_volume_thursday\").state) + msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":865,"y":255,"wires":[[]]},{"id":"048db3c93789a9da","type":"api-call-service","z":"470c561b7b7c90d9","name":"Add to Friday","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.linktap_main_spigot_volume_friday"],"data":"{\"value\": $number($entities(\"input_number.linktap_main_spigot_volume_friday\").state) + msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":855,"y":285,"wires":[[]]},{"id":"588cb41da5a52a7c","type":"api-call-service","z":"470c561b7b7c90d9","name":"Add to Saturday","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.linktap_main_spigot_volume_saturday"],"data":"{\"value\": $number($entities(\"input_number.linktap_main_spigot_volume_saturday\").state) + msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":865,"y":315,"wires":[[]]},{"id":"1ac1bcda18b1ccee","type":"api-call-service","z":"470c561b7b7c90d9","name":"Add to Sunday","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.linktap_main_spigot_volume_sunday"],"data":"{\"value\": $number($entities(\"input_number.linktap_main_spigot_volume_sunday\").state) + msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":865,"y":345,"wires":[[]]},{"id":"4395e1fd43c7f741","type":"api-call-service","z":"470c561b7b7c90d9","name":"Add to lifetime","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.linktap_main_spigot_volume_lifetime"],"data":"{\"value\": $number($entities(\"input_number.linktap_main_spigot_volume_lifetime\").state) + msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":135,"wires":[[]]},{"id":"ab3e2c53.e3491","type":"server","name":"AvilaSmartHome","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"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}]

Looks like JSONata.

You have a choice of $round(number, precision) or $floor(number), and you can round just the returned state, or the sum including the payload. $number() does seem to generate floats with many decimal places, even for integers, so I used $round(x, 1) or similar quite a lot.

This should do the trick.

{"value": $round($number($entities("input_number.linktap_main_spigot_volume_sunday").state) + payload, 0)}

Incidentally, JSONata now uses the message as the top level document, thus ‘msg.’ is no longer required, just the ‘payload’ bit. If you use ‘msg.payload’ you will see ’ compatibility mode enabled’ in the JSONata editor, and clicking on this will give the warning that ‘msg.’ should not be used.

Hope this helps

@Biscuit , worked great! Anyway to change this to rounding also?
image

{{ states('sensor.linktap_main_spigot_volume') }}

That looks like standard template (Jinja) so, again, you have a choice.

round(number, precision) would do the job, but this always rounds a float value to a float, even for 0 precision.

int(default) turns any number into an integer, but does so by truncation, ie floor.

Using the ‘|’ Jinja filter operator, the first parameter is taken from context, hence the following returns a float value with no decimal places

{{ states(‘sensor.linktap_main_spigot_volume’)|round(0) }}

If you want to both round, and produce an integer, then the following should do the trick

{{ states('sensor.linktap_main_spigot_volume')|round(0)|int }}