Help with calculation with mqtt

Hi
I have something fairly basic to do, but I cant get my head around it.

I have 2 sensors I need to multiply, and divide by 10.
so:

  1. sensor.solis_mqtt_dc1_voltage
  2. sensor.solis_mqtt_dc1_current

voltage 1 is x10 though.
‘’’
-name: “MQTT PV1 power”
value_template: "{{states(‘sensor.solis_mqtt_dc1_voltage’) / 10 ) | float} x states(‘sensor.solis_mqtt_dc1_current’) | float}}
‘’’

but it wont work - i dont get it!

help would be appreciated, as I dont seem to be able to pull the actual power from the inverter through mqtt.

If you are trying to create a Template Sensor that performs a calculation using the values of other sensors, you can do it like this:

template:
  - sensor:
      - name: "MQTT PV1 power"
        state: "{{ (states('sensor.solis_mqtt_dc1_voltage') | float(0) / 10) * states('sensor.solis_mqtt_dc1_current') | float(0) }}"

Reference: Template Sensor


EDIT

Correction. Added missing {{ to template.

1 Like

Hi thanks for that.
Ive put that in, but it doesnt actually do the calculation for me: it just says that string as the value.

That’s due to my mistake. I overlooked to include {{ in the template. Without it, it’s not evaluated as a Jinja2 template but merely as a string. I have corrected the example above.

1 Like