ESPHOME derive new custom sensor from two other sensors

I’m trying to derive a custom sensor from two other sensors using templates or lambda, but I’m hitting a brick wall. This is the yaml containing the two sensors and the custom sensor I was trying to derive, Can someone please help me check what I was doing wrong. Thanks in advance.

  - platform: pipsolar
    pipsolar_id: inverter0
    # QPIRI
    # QPIGS
      name: "${name} pv_voltage"
      id: pvvoltage
      unit_of_measurement: "V"
      name: "${name} battery_voltage"
      id: batteryvoltage
      unit_of_measurement: "V"
      name: "${name} pv_current"
      id: pvcurrent
      unit_of_measurement: "A"

  - platform: template
    name: "${name} pv_power"
    id: pv_power
      - lambda: return id(pvcurrent).raw_state) * id(batteryvoltage).raw_state);
    update_interval: 10s

What exact error do you ge
First off, try removing the closing bracket after _state (both instances).

 - lambda: return id(pvcurrent).raw_state * id(batteryvoltage).raw_state;

Thank you, I changed it to this and it works.

    lambda: |-
     return (id(batteryvoltage).raw_state * id(pvcurrent).raw_state);

Is there any need to remove the parenthesis before id and before the semi-colon?

No absolute need, but they have no effect, as the whole expression is evaluated before return anyway :slight_smile:

1 Like