WTH Helpers can do calculus but not arithmetic?!?

It’s great to be able to do derivatives and integrals but not being able to simple add/subtract two sensor values with helpers seems odd.

Same with simple is X>Y; would be great to have simple logic inputs/outputs in helper form instead of templates.

An arithmetic helper?

Nice idea. +1

I thought about adding this a long time ago, but a subtract doesn’t make sense. Add does, you can list out n entities and it adds them. But what about subtract… everything is subtracted from the first value? Seems odd to me. Either way, it’s a new integration so it doesn’t really fall into the scope of wth.

Yeah BODMAS would be a nightmare to enforce.

This should probably be a separate WTH actually. WTH does the threshold helper not allow a numeric entity instead of a hard-coded number?

1 Like

I think id prefer a template sensor helper. Sum is a slippery slope. Then we have to add subtract, multiply, divide and so on.

What is the easiest way to scale a sensor output or perform other mathematical operations on a sensor output and be able to use that output within automations?

By using this to create the scaled entity:

#I added the following to configuration.yaml and restarted HA.

# configuration.yaml entry for Compensation integration on Solar panel power estimator
    source: sensor.small_solar_panel_voltage
    #attribute: volume_level
    unit_of_measurement: W
      - [0.00, 0.00]
      - [9.15, 8.00]

#Should I see a new entity in in the entities list?  Where can I find the scaled output and will it's name be "estimated_pv_panel_power"

I just added a “unique_id” configuration variable and now it shows up. Once its sunny, I will check on the values.

The Compensation entity worked very well for scaling the sensor input, at least for the first 60% of the function where the relationship is linear. I see that the integration supports higher degrees. Is there a general rule of how many data_points are needed for higher degrees? If I add more points, but keep the degree at 1, will I get a piece wise or segmented linear compensation?

Is there a way that the value from another sensor could be subtracted from the compensated value to create an entity with a net result?

Each degree needs degree+1 points.

No, it compensates the entire set with 1 degree polynomial. What you’re describing is called ‘interpolation’. It’s something I’ve wanted to add to it, but haven’t come up with a good way of handling it without breaking changes.

Template sensors can do that.

1 Like

I have been collecting data points and configured the following compensation integration:

    source: sensor.small_solar_panel_voltage
    unique_id: estimated_pv_panel_power
    precision: 0  
    unit_of_measurement: W
    degree: 2
      - [0.0095, 0]
      - [4.61, 4120]
#      - [4.90, 4420]
#      - [5.28, 4970]
#      - [5.49, 5400]
#      - [5.65, 5720]
#      - [5.73, 6050]
      - [6.094, 8200]

Whenever I try to include the data points that are commented out, the output goes to extremely high positive and negative values in the hundreds of thousands. As soon as I try increasing the number of degrees from two to three, and including the next commented out data point, the output goes wild again. What causes this? Are my data points too similar to one another? Is the zero output in the first data point a problem?

Is there a way to test updates to the compensation, without restarting HA? For the filters that follow the compensation, I can use Filter Entities button in the YAML configuration reloading page. Is there something similar for the compensation integration?

Because a 2 degree polynomial is a parabola.

Try setting the number of degrees equal to the number of points minus one.

I have tried increasing to 7 degrees and using all 8 data points, and the output goes out of control. This is the compensation curve that I am trying to achieve (the green line).

That green line is linear interpolation, this does not do that.

Can you give me the full list of datapoints that you have? I think - 3rd order will work but I’d need to play

This is all of the data that I have captured:
0.0095, 0
0.63, 530
0.49, 410
2.67, 2230
3.05, 2620
3.29, 2850
3.81, 3380
4.23, 3770
4.61, 4120
4.9, 4420
5.18, 4580
5.42, 5230
5.45, 5300
5.53, 4870
5.65, 5720
5.73, 6050
5.58, 5630
5.41, 5160
5.43, 5220
5.43, 5250
5.49, 5330
5.48, 5390
5.49, 5400
5.44, 5430
5.07, 4610
5.11, 4670
5.19, 4780
5.25, 4850
5.28, 4970
5.31, 5050
5.38, 5210
5.5, 5420
5.52, 5560
6.094, 8200

what’s the working range? 0 to 6?

Yes, 0 to about 6. It could be slightly higher or lower, but not much.