Input numbers

Due to issues with my newly installed smart meters, I am relying on Glowmarkt readings daily that are incomplete for the Gas cost.

That cost is always 0 for the day but the consumption is returned.

Currently I have managed to get the consumption recorded in a input_number and also the zero cost in an input_number too (in the hope that some of theses issues are fixed someday).

In total, I have 4 input numbers to work with and want to somehow calculate the actual gas cost in node red, then send this to a call_service to set the correct cost value. As I am already updating the cost via a call_service with the incorrect 0 value, I believe I understand that part and just need a calculated cost in the message payload. However, I am finding input_numbers in node-red to be tricky to work with. I could have an automation outside that is triggered once the gas consumption is retrieved but would really like the full flow to be in node red.

My input_numbers (all set as 0.00000 to 9999.99999 currently) are below in the algorithm/calculation I would like to create:

if input_number.todays_gas_cost = 0
then
input_number.todays_gas_cost =
input_number.gas_standing_charge_in_pence + (input_number.gas_tariff_in_pence *
input_number.todays_gas_consumption)

How do I get that into nodes in node-red?

[{"id":"019750856dc0db88","type":"api-current-state","z":"1f4df904e908b3bb","name":"charge","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.gas_standing_charge_in_pence","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"charge","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":302,"y":176,"wires":[["3e14467826cca23b"]]},{"id":"3e14467826cca23b","type":"api-current-state","z":"1f4df904e908b3bb","name":"tariff","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.gas_tariff_in_pence","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"tariff","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":430,"y":176,"wires":[["5e611fbd420668c8"]]},{"id":"5e611fbd420668c8","type":"api-current-state","z":"1f4df904e908b3bb","name":"consumption","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.todays_gas_consumption","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"consumption","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":574,"y":176,"wires":[["562ba695ad303dff"]]},{"id":"562ba695ad303dff","type":"api-call-service","z":"1f4df904e908b3bb","name":"","server":"","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":[],"data":"{\"value\": charge + ( tariff * consumption)}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":782,"y":176,"wires":[[]]},{"id":"bd3c05338bd2a474","type":"server-state-changed","z":"1f4df904e908b3bb","name":"today's cost","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.todays_gas_cost","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"0","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":150,"y":176,"wires":[["019750856dc0db88"],[]]},{"id":"e1e2b0c92efccdbb","type":"api-call-service","z":"1f4df904e908b3bb","name":"","server":"","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":[],"data":"(\t    $pence := $number($entities(\"input_number.gas_standing_charge_in_pence\").state);\t    $tariff := $number($entities(\"input_number.gas_tariff_in_pence \").state);\t    $consumption := $number($entities(\"input_number.todays_gas_consumption\").state);\t\t    {\"value\": $pence + ( $tariff * $consumption)}\t)","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":366,"y":224,"wires":[[]]},{"id":"c973efa37f6bb25d","type":"server-state-changed","z":"1f4df904e908b3bb","name":"today's cost","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.todays_gas_cost","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"0","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":150,"y":224,"wires":[["e1e2b0c92efccdbb"],[]]}]

Thanks for the nodes. Still having issues though when implementing your nodes. I am in Home Assistant, using the node-red addon but, even so, it does not like the $entities function. It does not appear in my list of functions within nodes and I get the “Invalid JSONata expression: Attempted to invoke a non-function” message.

The editor within the node also backs this up as it is not displayed in blue.

UPDATE: Actually, just got mixed up with 2 nodes output.

However I am getting “Call-service error. required key not provided @ data[‘value’]” so I have some kind of issue

might be because i added an extra space after pence

$tariff := $number($entities("input_number.gas_tariff_in_pence ").state);

Double-check and make sure all the entity names are correct.

You were correct thanks. I had checked the names but did not spot the space. Cheers, that’s great. Would flag that as a solution but no option showing… sorry

For anybody reading this,

SOLUTION IS POST #2 BY Kermit

[{"id":"019750856dc0db88","type":"api-current-state","z":"1f4df904e908b3bb","name":"charge","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.gas_standing_charge_in_pence","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"charge","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":302,"y":176,"wires":[["3e14467826cca23b"]]},{"id":"3e14467826cca23b","type":"api-current-state","z":"1f4df904e908b3bb","name":"tariff","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.gas_tariff_in_pence","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"tariff","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":430,"y":176,"wires":[["5e611fbd420668c8"]]},{"id":"5e611fbd420668c8","type":"api-current-state","z":"1f4df904e908b3bb","name":"consumption","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.todays_gas_consumption","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"consumption","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":574,"y":176,"wires":[["562ba695ad303dff"]]},{"id":"562ba695ad303dff","type":"api-call-service","z":"1f4df904e908b3bb","name":"","server":"","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":[],"data":"{\"value\": charge + ( tariff * consumption)}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":782,"y":176,"wires":[[]]},{"id":"bd3c05338bd2a474","type":"server-state-changed","z":"1f4df904e908b3bb","name":"today's cost","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.todays_gas_cost","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"0","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":150,"y":176,"wires":[["019750856dc0db88"],[]]},{"id":"e1e2b0c92efccdbb","type":"api-call-service","z":"1f4df904e908b3bb","name":"","server":"","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":[],"data":"(\t    $pence := $number($entities(\"input_number.gas_standing_charge_in_pence\").state);\t    $tariff := $number($entities(\"input_number.gas_tariff_in_pence\").state);\t    $consumption := $number($entities(\"input_number.todays_gas_consumption\").state);\t\t    {\"value\": $pence + ( $tariff * $consumption)}\t)","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":366,"y":224,"wires":[[]]},{"id":"c973efa37f6bb25d","type":"server-state-changed","z":"1f4df904e908b3bb","name":"today's cost","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.todays_gas_cost","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"0","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":150,"y":224,"wires":[["e1e2b0c92efccdbb"],[]]}]
1 Like