How to set charging state from a calculated sensor value
See original GitHub issueI’m trying to show a charging state indicator using a calculated value. I have a mini lora weather station based on a Heltec cubecell dev board, which doesn’t provide charging information on it’s own. I could try to calculate the charging information on the board by averaging the last n battery voltage measurements, but then I have to get to it and reprogram it. So I tried to do the calculation in home assistant. For this purpose I’m using a derivative sensor. The sensor itself works. It shows values above zero when the battery is charging from the solar panel and zero or below when it’s is going down over night.
Don’t know what caused the peak at 5am…
YAML configuration
entities:
- entity: sensor.outdoor_01_battery_level
name: Wetterstation
charging_state:
entity_id: sensor.outdoor_01_derivative
value: 0
operator: '>'
title: Batteriestatus
type: custom:battery-state-card
My expectation was that I can compare the sensor.outdoor_01_derivative to a value directly, but this doesn’t seem to work as expected. No matter if I set the operator to <
or >
, the charging indicator is always shown as in the screenshots below.
- Is there an error in the configuration?
- Is the delta (in the range of -0.01V…+0.01V per hour) too small for the comparison?
- Should I make a binary sensor based on the derivative sensor and use this instead?
Screenshot
>
comparison
<
comparison
Version V2.1.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Hey! There is no such a thing like operator for charging_state. Please look at documentation: https://github.com/maxwroc/battery-state-card#charging-state-object
To solve your problem (as you said) you need to create a separate template (binary) sensor, where you will have your condition, and use it in charging_state config.
OK, solved it with a combination of derivative/threshold sensor. Just for posterity if anyone comes across this problem too:
In sensors.yaml I defined a derivative sensor that monitors the incoming battery voltages over the past hour. Rounded to three digits in my case, because the changes are very small:
In binary_sensors.yaml I defined a threshold sensor that returns
on
when the derivative is above zero (which means the voltage is rising).The card configuration:
returns the expected result:
So really no need to add it to battery state card once you get your head around it.
Thanks again!