some stats
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
import globals
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
#
|
||||
# POwer theory
|
||||
# Power theory tariff switch
|
||||
#
|
||||
# Args:
|
||||
#
|
||||
# None
|
||||
#
|
||||
# Release Notes
|
||||
#
|
||||
# Version 1.0:
|
||||
# Initial Version
|
||||
|
||||
class PowerTheory(hass.Hass):
|
||||
def initialize(self):
|
||||
self.run_daily(self.timer_tick, self.parse_time("07:00:00"))
|
||||
self.run_daily(self.timer_tick, self.parse_time("10:00:00"))
|
||||
self.run_daily(self.timer_tick, self.parse_time("17:00:00"))
|
||||
self.run_daily(self.timer_tick, self.parse_time("21:00:00"))
|
||||
self.run_daily(self.timer_tick, self.parse_time("23:00:00"))
|
||||
self.timer_tick(None)
|
||||
|
||||
def timer_tick(self, kwargs):
|
||||
t1 = self.time_is_between(self.datetime(), '07:00:00', '10:00:00') or self.time_is_between(self.datetime(), '17:00:00', '21:00:00')
|
||||
t2 = self.time_is_between(self.datetime(), '23:00:00', '07:00:00')
|
||||
t3 = self.time_is_between(self.datetime(), '10:00:00', '17:00:00') or self.time_is_between(self.datetime(), '21:00:00', '23:00:00')
|
||||
if t1:
|
||||
self.switch_to_tariff('t1')
|
||||
if t2:
|
||||
self.switch_to_tariff('t2')
|
||||
if t3:
|
||||
self.switch_to_tariff('t3')
|
||||
|
||||
def switch_to_tariff(self, tariff):
|
||||
self.log('switching to power tariff: {}'.format(tariff))
|
||||
self.call_service("utility_meter/select_tariff", entity_id='utility_meter.power_theory', tariff=tariff)
|
||||
|
||||
|
||||
|
||||
def time_is_between(
|
||||
hass, target_dt: datetime, start_time: str,
|
||||
end_time: str) -> bool:
|
||||
"""Generalization of AppDaemon's now_is_between method."""
|
||||
start_time_dt = hass.parse_time(start_time) # type: datetime
|
||||
end_time_dt = hass.parse_time(end_time) # type: datetime
|
||||
start_dt = target_dt.replace(
|
||||
hour=start_time_dt.hour,
|
||||
minute=start_time_dt.minute,
|
||||
second=start_time_dt.second)
|
||||
end_dt = target_dt.replace(
|
||||
hour=end_time_dt.hour,
|
||||
minute=end_time_dt.minute,
|
||||
second=end_time_dt.second)
|
||||
|
||||
if end_dt < start_dt:
|
||||
# Spans midnight
|
||||
if target_dt < start_dt and target_dt < end_dt:
|
||||
target_dt = target_dt + timedelta(days=1)
|
||||
end_dt = end_dt + timedelta(days=1)
|
||||
return start_dt <= target_dt <= end_dt
|
||||
@@ -0,0 +1,5 @@
|
||||
power_theory:
|
||||
module: power_theory
|
||||
class: PowerTheory
|
||||
global_dependencies:
|
||||
- globals
|
||||
@@ -0,0 +1,14 @@
|
||||
- platform: template
|
||||
sensors:
|
||||
counter_hot_cost:
|
||||
friendly_name: "Стимость куба горячей воды"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "188.53"
|
||||
counter_cold_cost:
|
||||
friendly_name: "Стимость куба холодной воды"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "38.06"
|
||||
power_cost:
|
||||
friendly_name: "Стоимость квт/ч"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "4.37"
|
||||
@@ -2,33 +2,113 @@
|
||||
sensors:
|
||||
counter_hot_money_monthly:
|
||||
friendly_name: "Горячая в мес"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "{{ (states('sensor.counter_hot_monthly') | float * 188.53) | round(2) }}"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.counter_hot_monthly') | float * (states('sensor.counter_hot_cost') | float)) | round(2) }}"
|
||||
counter_cold_money_monthly:
|
||||
friendly_name: "Холодная в мес"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "{{ (states('sensor.counter_cold_monthly') | float * 38.06) | round(2) }}"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.counter_cold_monthly') | float * (states('sensor.counter_cold_cost') | float)) | round(2) }}"
|
||||
power_money_monthly:
|
||||
friendly_name: "Электричество в мес"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "{{ (states('sensor.power_monthly') | float * 4.37) | round(2) }}"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_monthly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
dishwasher_money_monthly:
|
||||
friendly_name: "Посудомойка в мес"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "{{ (states('sensor.dishwasher_monthly') | float * 4.37) | round(2) }}"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.dishwasher_monthly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
washer_money_monthly:
|
||||
friendly_name: "Стиралка в мес"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "{{ (states('sensor.washer_monthly') | float * 4.37) | round(2) }}"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.washer_monthly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
tv_money_monthly:
|
||||
friendly_name: "ТВ в мес"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "{{ (states('sensor.tv_monthly') | float * 4.37) | round(2) }}"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.tv_monthly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
thermopot_money_monthly:
|
||||
friendly_name: "Термопот в мес"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "{{ (states('sensor.thermopot_monthly') | float * 4.37) | round(2) }}"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.thermopot_monthly2') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
conditioner_money_monthly:
|
||||
friendly_name: "Кондиционер в мес"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "{{ (states('sensor.conditioner_monthly') | float * 4.37) | round(2) }}"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.conditioner_monthly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
power_money_t1_monthly:
|
||||
friendly_name: "Т1 в мес"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_theory_t1') | float * 1.37) | round(2) }}"
|
||||
power_money_t2_monthly:
|
||||
friendly_name: "Т2 в мес"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_theory_t2') | float * 4.37) | round(2) }}"
|
||||
power_money_t3_monthly:
|
||||
friendly_name: "Т3 в мес"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_theory_t3') | float * 5.25) | round(2) }}"
|
||||
|
||||
|
||||
|
||||
counter_hot_money_daily:
|
||||
friendly_name: "Горячая в день"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.counter_hot_daily') | float * (states('sensor.counter_hot_cost') | float)) | round(2) }}"
|
||||
counter_cold_money_daily:
|
||||
friendly_name: "Холодная в день"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.counter_cold_daily') | float * (states('sensor.counter_cold_cost') | float)) | round(2) }}"
|
||||
power_money_daily:
|
||||
friendly_name: "Электричество в день"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_daily') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
dishwasher_money_daily:
|
||||
friendly_name: "Посудомойка в день"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.dishwasher_daily') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
washer_money_daily:
|
||||
friendly_name: "Стиралка в день"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.washer_daily') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
tv_money_daily:
|
||||
friendly_name: "ТВ в день"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.tv_daily') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
thermopot_money_daily:
|
||||
friendly_name: "Термопот в день"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.thermopot_daily2') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
conditioner_money_daily:
|
||||
friendly_name: "Кондиционер в день"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.conditioner_daily') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
|
||||
counter_hot_money_hourly:
|
||||
friendly_name: "Горячая в час"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.counter_hot_hourly') | float * (states('sensor.counter_hot_cost') | float)) | round(2) }}"
|
||||
counter_cold_money_hourly:
|
||||
friendly_name: "Холодная в час"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.counter_cold_hourly') | float * (states('sensor.counter_cold_cost') | float)) | round(2) }}"
|
||||
power_money_hourly:
|
||||
friendly_name: "Электричество в час"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_hourly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
dishwasher_money_hourly:
|
||||
friendly_name: "Посудомойка в час"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.dishwasher_hourly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
washer_money_hourly:
|
||||
friendly_name: "Стиралка в час"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.washer_hourly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
tv_money_hourly:
|
||||
friendly_name: "ТВ в час"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.tv_hourly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
thermopot_money_hourly:
|
||||
friendly_name: "Термопот в час"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.thermopot_hourly2') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
conditioner_money_hourly:
|
||||
friendly_name: "Кондиционер в час"
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.conditioner_hourly') | float * (states('sensor.power_cost') | float)) | round(2) }}"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
conditioner_hourly:
|
||||
source: sensor.conditioner_consumed
|
||||
cycle: hourly
|
||||
conditioner_dialy:
|
||||
conditioner_daily:
|
||||
source: sensor.conditioner_consumed
|
||||
cycle: daily
|
||||
conditioner_monthly:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
dishwasher_hourly:
|
||||
source: sensor.dishwasher_consumed
|
||||
cycle: hourly
|
||||
dishwasher_dialy:
|
||||
dishwasher_daily:
|
||||
source: sensor.dishwasher_consumed
|
||||
cycle: daily
|
||||
dishwasher_monthly:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
power_hourly:
|
||||
source: sensor.power_total
|
||||
cycle: hourly
|
||||
power_dialy:
|
||||
power_daily:
|
||||
source: sensor.power_total
|
||||
cycle: daily
|
||||
power_monthly:
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
power_theory:
|
||||
source: sensor.power_total
|
||||
cycle: monthly
|
||||
tariffs:
|
||||
- t1
|
||||
- t2
|
||||
- t3
|
||||
@@ -1,7 +1,7 @@
|
||||
thermopot_hourly2:
|
||||
source: sensor.thermopot_consumed2
|
||||
cycle: hourly
|
||||
thermopot_dialy2:
|
||||
thermopot_daily2:
|
||||
source: sensor.thermopot_consumed2
|
||||
cycle: daily
|
||||
thermopot_monthly2:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
tv_hourly:
|
||||
source: sensor.tv_consumed
|
||||
cycle: hourly
|
||||
tv_dialy:
|
||||
tv_daily:
|
||||
source: sensor.tv_consumed
|
||||
cycle: daily
|
||||
tv_monthly:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
washer_hourly:
|
||||
source: sensor.washer_consumed
|
||||
cycle: hourly
|
||||
washer_dialy:
|
||||
washer_daily:
|
||||
source: sensor.washer_consumed
|
||||
cycle: daily
|
||||
washer_monthly:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
counter_cold_hourly:
|
||||
source: sensor.counter_cold
|
||||
cycle: hourly
|
||||
counter_cold_dialy:
|
||||
counter_cold_daily:
|
||||
source: sensor.counter_cold
|
||||
cycle: daily
|
||||
counter_cold_monthly:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
counter_hot_hourly:
|
||||
source: sensor.counter_hot
|
||||
cycle: hourly
|
||||
counter_hot_dialy:
|
||||
counter_hot_daily:
|
||||
source: sensor.counter_hot
|
||||
cycle: daily
|
||||
counter_hot_monthly:
|
||||
|
||||
@@ -185,65 +185,91 @@ views:
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.power_hourly
|
||||
- sensor.power_dialy
|
||||
- sensor.power_daily
|
||||
- sensor.power_monthly
|
||||
- sensor.power_money_hourly
|
||||
- sensor.power_money_daily
|
||||
- sensor.power_money_monthly
|
||||
- type: entities
|
||||
title: "Горячая вода"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.counter_hot_hourly
|
||||
- sensor.counter_hot_dialy
|
||||
- sensor.counter_hot_daily
|
||||
- sensor.counter_hot_monthly
|
||||
- sensor.counter_hot_money_hourly
|
||||
- sensor.counter_hot_money_daily
|
||||
- sensor.counter_hot_money_monthly
|
||||
- type: entities
|
||||
title: "Холодная вода"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.counter_cold_hourly
|
||||
- sensor.counter_cold_dialy
|
||||
- sensor.counter_cold_daily
|
||||
- sensor.counter_cold_monthly
|
||||
- sensor.counter_cold_money_hourly
|
||||
- sensor.counter_cold_money_daily
|
||||
- sensor.counter_cold_money_monthly
|
||||
- type: entities
|
||||
title: "Посудомойка"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.dishwasher_hourly
|
||||
- sensor.dishwasher_dialy
|
||||
- sensor.dishwasher_daily
|
||||
- sensor.dishwasher_monthly
|
||||
- sensor.dishwasher_money_hourly
|
||||
- sensor.dishwasher_money_daily
|
||||
- sensor.dishwasher_money_monthly
|
||||
- type: entities
|
||||
title: "Стиралка"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.washer_hourly
|
||||
- sensor.washer_dialy
|
||||
- sensor.washer_daily
|
||||
- sensor.washer_monthly
|
||||
- sensor.washer_money_hourly
|
||||
- sensor.washer_money_daily
|
||||
- sensor.washer_money_monthly
|
||||
- type: entities
|
||||
title: "Телевизор"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.tv_hourly
|
||||
- sensor.tv_dialy
|
||||
- sensor.tv_daily
|
||||
- sensor.tv_monthly
|
||||
- sensor.tv_money_hourly
|
||||
- sensor.tv_money_daily
|
||||
- sensor.tv_money_monthly
|
||||
- type: entities
|
||||
title: "Термопот"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.thermopot_hourly2
|
||||
- sensor.thermopot_dialy2
|
||||
- sensor.thermopot_daily2
|
||||
- sensor.thermopot_monthly2
|
||||
- sensor.thermopot_money_hourly
|
||||
- sensor.thermopot_money_daily
|
||||
- sensor.thermopot_money_monthly
|
||||
- type: entities
|
||||
title: "Кондиционер"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.conditioner_hourly
|
||||
- sensor.conditioner_dialy
|
||||
- sensor.conditioner_daily
|
||||
- sensor.conditioner_monthly
|
||||
- sensor.conditioner_money_hourly
|
||||
- sensor.conditioner_money_daily
|
||||
- sensor.conditioner_money_monthly
|
||||
- type: entities
|
||||
title: "Теория трехтарифника"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- sensor.power_theory_t1
|
||||
- sensor.power_theory_t2
|
||||
- sensor.power_theory_t3
|
||||
- sensor.power_money_t1_monthly
|
||||
- sensor.power_money_t2_monthly
|
||||
- sensor.power_money_t3_monthly
|
||||
- title: "Настройки"
|
||||
icon: mdi:settings
|
||||
cards:
|
||||
|
||||
Reference in New Issue
Block a user