I have two sensor entities and I want to multiply them together and output to a third sensor entity.
I feel this should be easy but lost as to how to achieve this in the least amount of steps.
Appreciate thoughts.
I have two sensor entities and I want to multiply them together and output to a third sensor entity.
I feel this should be easy but lost as to how to achieve this in the least amount of steps.
Appreciate thoughts.
Add two current state nodes, one per sensor. Ensure “State type” is set to number and ensure “State location” is set to a different thing in each (if they are both set to payload then the second will overwrite the first).
After that drop an entity node. On the state field change the dropdown from msg.
to jsonata and put state_1 * state_2
(replace state_1
and state_2
with whatever you used for state location in the two current state nodes).
There’s lots of ways to do anything in Node RED but that seems like the most straightforward.
Or alternatively if your 3rd sensor is always equal to the first sensor multiplied by the second sensor and you want its state to be updated any time the other two change then its probably easiest to just drop this in Home Assistant instead of trying to do it in Node RED:
template:
- sensor:
- name: Sensor 3
state: "{{ states('sensor.sensor_1') | number * states('sensor.sensor_2') | number }}"
I mean sure you can do that in Node RED but you need a whole bunch more steps and it will end up being a lot more difficult then that. Each platform has its strong points, trying to treat one as one size fits all usually ends up making your life more difficult. I like Node RED as an automation platform but HA is a much better state machine.
But only if you always want sensor 3 to be equal to sensor 1 & 2, if sensor 3 isn’t always a multiple of these two and is set differently in different automations then use a flow like I described above.
doesnt need more in nodered - you could simply put this in a template node
Thanks both, implemented via template.