dynamic groups are slow =(

This commit is contained in:
Your Name
2019-11-08 20:24:29 +03:00
parent 215d3af281
commit 43cdef8ee2
6 changed files with 356 additions and 169 deletions
+169
View File
@@ -4,3 +4,172 @@ uptime:
friendly_name: Аптайм
device_type: sensor
entity_part: "uptime_"
control_tags:
module: groups
class: Groups
device_type: input_boolean
entity_part: "tag_"
sensor_tags:
module: groups
class: Groups
device_type: sensor
entity_part: "tag_"
light_control:
module: groups
class: Groups
device_type: input_boolean
entity_part: "_light_control"
report_control:
module: groups
class: Groups
device_type: input_boolean
entity_part: "_report"
automation_control:
module: groups
class: Groups
device_type: input_boolean
entities:
- input_boolean.presence_control
- input_boolean.water_control
- input_boolean.water_leak_control
- input_boolean.mainroom_climate_control
- switch.domofon_mode
door_sensors:
module: groups
class: Groups
device_type: binary_sensor
entity_part: "door_window_sensor_"
orderby: friendly_name
smoke_sensors:
module: groups
class: Groups
device_type: binary_sensor
entity_part: "smoke_sensor_"
water_leak_sensors:
module: groups
class: Groups
device_type: binary_sensor
entity_part: "water_leak_sensor_"
orderby: friendly_name
motion_sensors:
module: groups
class: Groups
device_type: binary_sensor
entity_part: "motion_sensor_"
orderby: friendly_name
presence_sensors:
module: groups
class: Groups
device_type: sensor
entities:
- sensor.presence_
- sensor.toilet_presence
epd_water_counters:
module: groups
class: Groups
device_type: sensor
entities:
- sensor.epd_balance
- sensor.counter_hot
- sensor.counter_cold
- sensor.counter_mosru_hot
- sensor.counter_mosru_cold
power_sensors:
module: groups
class: Groups
device_type: sensor
entities:
- sensor.power_mosenergosbyt_balance
- sensor.power_main_total
- sensor.power_mosenergosbyt_total
- sensor.power_total
- sensor.power_voltage
- sensor.power_current
- sensor.power_frequency
- sensor.power_active_power
- sensor.power_reactive_power
- sensor.power_power_factor
home_entities:
module: groups
class: Groups
entities:
- alarm_control_panel.ha_alarm
- switch.water_valve
- vacuum.xiaomi_vacuum_cleaner
- switch.domofon_open
- switch.wifi_socket
room_livingroom_entities:
module: groups
class: Groups
expand_group: True
entities:
- sensor.temperature_158d0001149b3c
- sensor.humidity_158d0001149b3c
- sensor.xiaomi_airpurifier_air_quality_pm25
- group.mainroom_light
- light.salt_lamp
- cover.curtain_158d0002b0c46a
- switch.plug_158d0001104a0c
- switch.plug_158d00010dd98d
- fan.xiaomi_miio_device
- climate.living_room
room_kitchen_entities:
module: groups
class: Groups
expand_group: True
entities:
- group.kitchen_light
- switch.plug_158d0001a68b18
- switch.plug_158d0001a68c64
- switch.plug_158d0001a4cfb4
- switch.plug_158d00020f3a29
- switch.plug_158d0002924779
- switch.xiaomi_miio_switch
room_bath_entities:
module: groups
class: Groups
entities:
- sensor.temperature_158d00012d9ad7
- sensor.humidity_158d00012d9ad7
- light.bath
- light.philips_led
- sensor.airfresher_remain
room_hall_entities:
module: groups
class: Groups
entities:
- light.hall
room_balcony_entities:
module: groups
class: Groups
expand_group: True
entities:
- sensor.temperature_158d000117d37a
- sensor.humidity_158d000117d37a
- group.balcony_light
- switch.plug_158d00026ea017
room_outside_entities:
module: groups
class: Groups
entities:
- sensor.temperature_158d000149c128
- sensor.humidity_158d000149c128
@@ -54,9 +54,10 @@ class WorkTime(hass.Hass):
def run_timer(self):
if self.arrive_time == None:
return
if self.notify_time<self.datetime():
self.notify_time=self.datetime()+datetime.timedelta(seconds=self.notify_every_seconds)
self.timers.append(self.run_every(self.timer_tick, self.notify_time, self.notify_every_seconds))
timer_start = self.notify_time
if timer_start<self.datetime():
timer_start=self.datetime()+datetime.timedelta(seconds=self.notify_every_seconds)
self.timers.append(self.run_every(self.timer_tick, timer_start, self.notify_every_seconds))
def leave_event(self, event_id, event_args, kwargs):
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
@@ -78,6 +79,7 @@ class WorkTime(hass.Hass):
self.log("Monster leave work at {} - {}".format(self.arrive_time, self.datetime))
message = "Рабочий день окончен ({}-{}). Приятной дороги домой.{}".format(self.format_time(self.arrive_time), self.format_time(self.datetime()), travelTime)
self.notify(message, name = self.args['notify'])
# self.reset_timer_tick(None)
def timer_tick(self, args) -> None:
self.log('timer tick')
+3
View File
@@ -49,6 +49,9 @@ entity_config:
light.yeelight_mono1_34ce0087ff33:
name: "Люстра"
room: "Гостиная"
light.salt_lamp:
name: "Соляная лампа"
room: "Гостиная"
switch.wifi_socket:
name: "Гирлянда"
room: "Гостиная"
@@ -5,6 +5,7 @@
payload_not_available: "false"
state_topic: "home/noolite/ch0/power"
command_topic: "home/noolite/ch0/power/set"
on_command_type: first
payload_on: "on"
payload_off: "off"
brightness_state_topic: "home/noolite/ch0/brightness"
+145 -161
View File
@@ -1,51 +1,24 @@
#custom cards
resources:
- url: /community_plugin/auto-entities/auto-entities.js
type: module
- url: /community_plugin/lovelace-auto-entities/auto-entities.js
type: module
# This file was automatically generated by lovelace_migrate.py
# https://github.com/dale3h/python-lovelace
title: Home
views:
- title: "Статус"
icon: mdi:home
cards:
- type: custom:auto-entities
card:
type: entities
title: "Дом"
show_header_toggle: false
- type: entities
title: "Дом"
show_header_toggle: false
entities:
- alarm_control_panel.ha_alarm
- switch.water_valve
- vacuum.xiaomi_vacuum_cleaner
- switch.domofon_open
- switch.wifi_socket
- type: custom:auto-entities
card:
type: entities
title: "Ванная"
show_header_toggle: false
entities:
- sensor.temperature_158d00012d9ad7
- sensor.humidity_158d00012d9ad7
- light.bath
- light.philips_led
- sensor.airfresher_remain
- type: custom:auto-entities
card:
type: entities
title: "Улица"
show_header_toggle: false
entities:
- sensor.temperature_158d000149c128
- sensor.humidity_158d000149c128
- type: custom:auto-entities
card:
type: entities
title: "Гостиная"
show_header_toggle: false
- type: entities
title: "Гостиная"
show_header_toggle: false
entities:
- sensor.temperature_158d0001149b3c
- sensor.humidity_158d0001149b3c
@@ -54,18 +27,16 @@ views:
- light.yeelight_color1_286c071065c7
- light.yeelight_mono1_34ce0087ff33
- light.yeelight_mono1_f0b4290e5444
- light.yeelight_mono1_f0b429a8f6df
- light.yeelight_mono1_f0b429a8f6df
- light.salt_lamp
- cover.curtain_158d0002b0c46a
- switch.plug_158d0001104a0c
- switch.plug_158d00010dd98d
- fan.xiaomi_miio_device
- climate.living_room
- type: custom:auto-entities
card:
type: entities
title: "Кухня"
show_header_toggle: false
- type: entities
title: "Кухня"
show_header_toggle: false
entities:
- light.kitchen
- light.kitchen_mini_light
@@ -75,103 +46,108 @@ views:
- switch.plug_158d00020f3a29
- switch.plug_158d0002924779
- switch.xiaomi_miio_switch
- type: custom:auto-entities
card:
type: entities
title: "Прихожая"
show_header_toggle: false
- type: entities
title: "Ванная"
show_header_toggle: false
entities:
- sensor.temperature_158d00012d9ad7
- sensor.humidity_158d00012d9ad7
- light.bath
- light.philips_led
- sensor.airfresher_remain
- type: entities
title: "Прихожая"
show_header_toggle: false
entities:
- light.hall
- type: custom:auto-entities
card:
type: entities
title: "Балкон"
show_header_toggle: false
- type: entities
title: "Балкон"
show_header_toggle: false
entities:
- light.yeelight_mono1_286c07f12bed
- light.yeelight_mono1_f0b429a8d936
- sensor.temperature_158d000117d37a
- sensor.humidity_158d000117d37a
- switch.plug_158d00026ea017
- type: entities
title: "Улица"
show_header_toggle: false
entities:
- sensor.temperature_158d000149c128
- sensor.humidity_158d000149c128
- title: "Датчики"
icon: mdi:nfc
cards:
- type: custom:auto-entities
card:
type: entities
title: "Движение"
show_header_toggle: false
filter:
include:
- entity_id: "/sensor.motion_sensor_.*/"
sort:
method: name
- type: custom:auto-entities
card:
type: entities
title: "Протечка"
show_header_toggle: false
filter:
include:
- entity_id: "/sensor.water_leak_sensor_.*/"
sort:
method: name
- type: custom:auto-entities
card:
type: entities
title: "Датчики дыма"
show_header_toggle: false
filter:
include:
- entity_id: "/sensor.smoke_sensor_.*/"
sort:
method: name
- type: custom:auto-entities
card:
type: entities
title: "Двери"
show_header_toggle: false
filter:
include:
- entity_id: "/sensor.door_window_sensor_.*/"
sort:
method: name
- type: custom:auto-entities
card:
type: entities
title: "Счетчики воды"
show_header_toggle: false
- type: entities
title: "Движение"
show_header_toggle: false
entities:
- binary_sensor.motion_sensor_158d0000e7c7ad
- binary_sensor.motion_sensor_158d0002044548
- binary_sensor.motion_sensor_158d0000fbc664
- binary_sensor.motion_sensor_158d0001535c97
- binary_sensor.motion_sensor_158d0000f9546b
- binary_sensor.motion_sensor_158d000165fed5
- binary_sensor.motion_sensor_158d0001537e21
- binary_sensor.motion_sensor_158d0000f6b2fa
- binary_sensor.motion_sensor_158d0001e50ce4
- binary_sensor.motion_sensor_158d0001e80f0d
- type: entities
title: "Протечка"
show_header_toggle: false
entities:
- binary_sensor.water_leak_sensor_158d0001d594fa
- binary_sensor.water_leak_sensor_158d0001c34960
- binary_sensor.water_leak_sensor_158d0002150c07
- binary_sensor.water_leak_sensor_158d0002112b98
- binary_sensor.water_leak_sensor_158d0002113158
- binary_sensor.water_leak_sensor_158d00023a48f0
- type: entities
title: "Датчики дыма"
show_header_toggle: false
entities:
- binary_sensor.smoke_sensor_158d00023115ad
- type: entities
title: "Двери"
show_header_toggle: false
entities:
- binary_sensor.door_window_sensor_158d0001130141
- binary_sensor.door_window_sensor_158d000111a469
- binary_sensor.door_window_sensor_158d00010f7e19
- binary_sensor.door_window_sensor_158d0002254373
- binary_sensor.door_window_sensor_158d0001b77b1b
- binary_sensor.door_window_sensor_158d0001c0e46d
- binary_sensor.door_window_sensor_158d0001e74660
- binary_sensor.door_window_sensor_158d0001b711ec
- type: entities
title: "Счетчики воды"
show_header_toggle: false
entities:
- sensor.epd_balance
- sensor.counter_hot
- sensor.counter_cold
- sensor.counter_mosru_hot
- sensor.counter_hot
- sensor.counter_mosru_cold
- type: custom:auto-entities
card:
type: entities
title: "Метки"
show_header_toggle: false
filter:
include:
- entity_id: "/sensor.tag_.*/"
- type: custom:auto-entities
card:
type: entities
title: "Пристутствие"
show_header_toggle: false
- sensor.counter_mosru_hot
- type: entities
title: "Метки"
show_header_toggle: false
entities:
- sensor.tag_mamik_band
- sensor.tag_monster_nut
- sensor.tag_nut_blue
- sensor.tag_nut_white
- sensor.tag_nut_guest
- type: entities
title: "Пристутствие"
show_header_toggle: false
entities:
- sensor.presence_hall
- sensor.presence_kitchen
- sensor.presence_balcony
- sensor.toilet_presence
filter:
include:
- entity_id: "/sensor.presence_.*/"
sort:
method: name
- type: custom:auto-entities
card:
type: entities
title: "Электропитание"
show_header_toggle: false
- type: entities
title: "Электропитание"
show_header_toggle: false
entities:
- sensor.power_mosenergosbyt_balance
- sensor.power_main_total
@@ -196,13 +172,15 @@ views:
icon: mdi:alarm
cards:
- type: entities
title: "Будильник (будни)"
title: "Будильник (бу\
дни)"
show_header_toggle: false
entities:
- input_boolean.alarmclock_weekdays
- input_datetime.alarmclock_weekdays
- type: entities
title: "Будильник (выходные)"
title: "Будильник (вы\
ходные)"
show_header_toggle: false
entities:
- input_boolean.alarmclock_weekend
@@ -340,49 +318,55 @@ views:
- title: "Настройки"
icon: mdi:settings
cards:
- type: custom:auto-entities
card:
type: entities
title: "Контроль света"
show_header_toggle: false
filter:
include:
- entity_id: "/input_boolean..*_light_control/"
- type: custom:auto-entities
card:
type: entities
title: "Настройки автоматики"
show_header_toggle: true
- type: entities
title: "Контроль све\
та"
show_header_toggle: true
entities:
- input_boolean.mainroom_light_control
- input_boolean.hall_light_control
- input_boolean.bath_light_control
- input_boolean.kitchen_light_control
- input_boolean.balcony_light_control
- type: entities
title: "Настройки ав\
томатики"
show_header_toggle: true
entities:
- input_boolean.presence_control
- input_boolean.water_control
- input_boolean.water_leak_control
- input_boolean.mainroom_climate_control
- switch.domofon_mode
- type: custom:auto-entities
card:
type: entities
title: "Настройки отчетов"
show_header_toggle: true
filter:
include:
- entity_id: "/input_boolean..*_report/"
- type: custom:auto-entities
card:
type: entities
title: "Метки"
show_header_toggle: true
filter:
include:
- entity_id: "/input_boolean.tag_.*/"
- type: custom:auto-entities
card:
type: entities
title: "Аптайм"
show_header_toggle: false
filter:
include:
- entity_id: "/sensor.uptime_.*/"
- type: entities
title: "Настройки отчетов"
show_header_toggle: true
entities:
- input_boolean.security_sensors_report
- input_boolean.battery_report
- input_boolean.water_counters_report
- input_boolean.work_presence_report
- input_boolean.lock_report
- type: entities
title: "Метки"
show_header_toggle: true
entities:
- input_boolean.tag_mamik_band
- input_boolean.tag_monster_nut
- input_boolean.tag_nut_blue
- input_boolean.tag_nut_white
- input_boolean.tag_nut_guest
- type: entities
title: "Аптайм"
show_header_toggle: false
entities:
- sensor.uptime_airfresher
- sensor.uptime_bath
- sensor.uptime_domofon
- sensor.uptime_kitchen_led
- sensor.uptime_nest
- sensor.uptime_bathlight
- sensor.uptime_kitchen
- title: "Информация"
icon: mdi:monitor-multiple
cards:
@@ -401,4 +385,4 @@ views:
entities:
- sensor.speedtest_ping
- sensor.speedtest_download
- sensor.speedtest_upload
- sensor.speedtest_upload
+33 -5
View File
@@ -5,6 +5,8 @@ import logging
import os
import re
import noolite
import queue
import threading
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@@ -23,7 +25,29 @@ config = {
Homie = homie.Homie(config)
nodes = {}
n = noolite.NooLite()
q = queue.Queue()
t = None
def queuee_worker():
n = noolite.NooLite()
while True:
item = q.get()
if item is None:
break
command = item.get('command', None)
channel = item.get('channel', None)
args = item.get('args', None)
if command == 'on':
n.on(channel)
elif command == 'off':
n.off(channel)
elif command == 'set':
n.set(channel, args)
elif command == 'bind':
n.bind(channel)
elif command == 'quit':
q.task_done()
time.sleep(0.3)
def brightnessHandler(mqttc, obj, msg):
try:
@@ -41,7 +65,7 @@ def brightnessHandler(mqttc, obj, msg):
brightness = int(payload)
ch_num = int(channel.replace('ch',''))
logger.info("[{}] brightness: {}".format(channel, brightness))
n.set(ch_num, brightness)
q.put({'command':'set', 'channel':ch_num,'args':brightness})
node.setProperty("brightness").send(brightness)
except Exception as e:
logger.error("Something gone wrong in brightnessHandler: {}!".format(e))
@@ -57,7 +81,7 @@ def bindHandler(mqttc, obj, msg):
return true
node = nodes[channel]
ch_num = int(channel.replace('ch',''))
n.bind(ch_num)
q.put({'command':'bind', 'channel':ch_num})
except Exception as e:
logger.error("Something gone wrong in bindHandler: {}!".format(e))
@@ -74,11 +98,11 @@ def powerHandler(mqttc, obj, msg):
ch_num = int(channel.replace('ch',''))
if payload == 'on' or payload == 'true':
logger.info("[{}] Power: on".format(channel))
n.on(ch_num)
q.put({'command':'on', 'channel':ch_num})
node.setProperty("power").send("on")
else:
logger.info("[{}] Power: off".format(channel))
n.off(ch_num)
q.put({'command':'off', 'channel':ch_num})
node.setProperty("power").send("off")
except Exception as e:
logger.error("Something gone wrong in powerHandler: {}!".format(e))
@@ -102,6 +126,8 @@ def main():
nodes[nodeName]=node
Homie.setup()
t = threading.Thread(target=queuee_worker)
t.start()
while True:
time.sleep(1)
@@ -110,4 +136,6 @@ if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit):
q.put({'command':'quit'})
t.join()
logger.info("Quitting.")