Avg price for tibber sensor (#18426)
* Avg price for tibber sensor * change to sum_price
This commit is contained in:
parent
7113ec6073
commit
7aa41d66e9
1 changed files with 5 additions and 0 deletions
|
@ -132,6 +132,8 @@ class TibberSensorElPrice(Entity):
|
|||
state = None
|
||||
max_price = 0
|
||||
min_price = 10000
|
||||
sum_price = 0
|
||||
num = 0
|
||||
now = dt_util.now()
|
||||
for key, price_total in self._tibber_home.price_total.items():
|
||||
price_time = dt_util.as_local(dt_util.parse_datetime(key))
|
||||
|
@ -146,8 +148,11 @@ class TibberSensorElPrice(Entity):
|
|||
if now.date() == price_time.date():
|
||||
max_price = max(max_price, price_total)
|
||||
min_price = min(min_price, price_total)
|
||||
num += 1
|
||||
sum_price += price_total
|
||||
self._state = state
|
||||
self._device_state_attributes['max_price'] = max_price
|
||||
self._device_state_attributes['avg_price'] = sum_price / num
|
||||
self._device_state_attributes['min_price'] = min_price
|
||||
return state is not None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue