Help with easy Multiplication for a new Entity

Hi there, im trying to get a entity wich gets me the chargingpower of my Tesla. I have voltage and current via mqtt in HA and need a new entity wich simply multiplies these two entities.

i tried to implement a template sensor but it’s not showing up in HA after restart. The configuration check in Dev Tools is ok.

This is my template_sensor.yaml wich is included in configuration.yaml

- sensor:
      - name: "Tesla Ladeleistung"
        unit_of_measurement: "W"
        state_class: power
        state: >
          {% set voltage = states('sensor.tesla_charger_voltage') | float %}
          {% set current = states('sensor.tesla_charger_current') | float %}

          {{ (voltage * current) | round(2) }}

What i have to do to get this entity to show up in HA? This is my first integration with the “Template” Sensor.

Thanks!

That looks pretty good. You just need to add some default values for your float filters and adding an availability template is a good idea too. Oh and you got state class mixed up with device class:

- sensor:
    - name: "Tesla Ladeleistung"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement 
      state: >
        {% set voltage = states('sensor.tesla_charger_voltage') | float(0) %}
        {% set current = states('sensor.tesla_charger_current') | float(0) %}
        {{ (voltage * current) | round(2) }}
      availability: >
        {{ states('sensor.tesla_charger_voltage') | is_number and 
           states('sensor.tesla_charger_current') | is_number }}

Thanks!

I also added "state_class: “measurement”.

Now it’s showing up and i can test it when the car is sharging next time. How often does the value gets updated? When one of the input sensors get updated?

Yes when either one of the source sensors changes the template will be re-evaluated.

1 Like

Hi I was trying this for a solar pv total, but not seeming to be able to display it in HA dash.

template:
 - sensor:
    - name: "PV2 Power"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement 
      state: >
        {% set voltage = states('sensor.solis_modbus_pv_voltage_2') | float(0) %}
        {% set current = states('sensor.solis_modbus_pv_current_2') | float(0) %}
        {{ (voltage * current) | round(2) }}
        availability: >
        {{ states('sensor.solis_modbus_pv_voltage_2') | is_number and 
           states('sensor.solis_modbus_pv_current_2') | is_number }}

416046400_7189805454406639_6337591847902728348_n

Look at the indentation of availability: ... in your sensor compared to,mine. It should be the same as state:.