Strange Behaviour on Applying Mathematics on Variable

Hello everyone,

I've recently been attempting to perform mathematical operations on a variable in my Home Assistant setup. The variable I'm working with is obtained from Home Assistant and is named comfort_temperature. Here's an example of what I'm doing and the unexpected results I'm getting:

var comfort_temperature = global.get('homeassistant.homeAssistant.states["input_number.bedroom_1_comfort_temperature"].state')
  • node.status({fill: 'green', shape: 'dot', text: "Temp: " + comfort_temperature + 2 }) Result: 16.02
  • node.status({fill: 'green', shape: 'dot', text: "Temp: " + comfort_temperature / 2 }) Result: 8
  • node.status({fill: 'green', shape: 'dot', text: "Temp: " + comfort_temperature * 2 }) Result: 32

I'm puzzled by these unexpected results and would appreciate any insights or assistance in understanding what's happening.

Thanks
Kalvin

Have successfully got this solved.

var comfort_temperature = parseFloat(global.get('homeassistant.homeAssistant.states["input_number.bedroom_1_comfort_temperature"].state'));

In case you did not realise, the problem was presumably that the value you were getting was a String not a Number. Calling parseFloat converts the string to a number.

1 Like

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