I need help for subtraction 2numbers output result

[{"id":"6b3775681e84575b","type":"server-state-changed","z":"4d1e24cc7a676365","name":"curren temp","server":"771a2737.fb6358","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":"温度"},{"property":"icon","value":"temperature"}],"entityidfilter":"sensor.zhi_neng_guang_gan_wen_du_ji_zigbeeban_temperature","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"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":90,"y":820,"wires":[["223d2af65e5291bb"]]},{"id":"c4d78c8452cd5157","type":"server-state-changed","z":"4d1e24cc7a676365","name":"target temp","server":"771a2737.fb6358","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.room1_temp","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"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":90,"y":760,"wires":[["223d2af65e5291bb"]]},{"id":"1797480146a4648f","type":"debug","z":"4d1e24cc7a676365","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":800,"wires":[]},{"id":"223d2af65e5291bb","type":"join","z":"4d1e24cc7a676365","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":330,"y":800,"wires":[["42175ef90592bb81","1797480146a4648f"]]},{"id":"42175ef90592bb81","type":"function","z":"4d1e24cc7a676365","name":"Subtraction","func":"msg.payload = sensor.zhi_neng_guang_gan_wen_du_ji_zigbeeban_temperature - input_number.room1_temp;\nmsg.topic = \"Number\";\nreturn msg;\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":740,"wires":[["1797480146a4648f"],[]]},{"id":"771a2737.fb6358","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

I want to make an automatic air conditioner, but the difference is that when the temperature is high, I want to control the increase in air volume instead of directly adjusting the temperature of the air conditioner.
I used hass to make an auxiliary that can be of type number as the target temperature

The temperature sensor is used as the current temperature! How to subtract them to get the difference.
Both payloads are numbers. I use join to put them together and then...

Here are the two payloads and topic

{"sensor.zhi_neng_guang_gan_wen_du_ji_zigbeeban_temperature":"28.5","input_number.room1_temp":"23.0"}

your payloads are strings, you would need to convert to numbers.
e.g

msg.payload = Number(sensor.zhi_neng_guang_gan_wen_du_ji_zigbeeban_temperature) - Number(input_number.room1_temp);
msg.topic = "Number";
return msg;

Strings are shown in debug with quotes around and red, numbers are blue

Its a little off-topic, but here is an Idea.

Use the range node?
transpose from 1 range to another.

This will allow a linear air volume output based on temp.

but as @E1cid mentioned - ensure they are numeric values

"ReferenceError: sensor is not defined (line 1, col 36)"

I made changes. It still doesn't work, I get this

msg.payload = Number(msg.payload["sensor.zhi_neng_guang_gan_wen_du_ji_zigbeeban_temperature"]) - Number(msg.payload["input_number.room1_temp"]);
msg.topic = "Number";
return msg;
1 Like

MAGIC~! it worked...

thanks you so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.