updating configuration
This commit is contained in:
@@ -7,7 +7,4 @@ RUN pip3 install \
|
||||
emp_mos_api==0.10 \
|
||||
packaging==16.8 \
|
||||
python-Levenshtein==0.12.0 \
|
||||
voluptuous==0.11.5 \
|
||||
noolite==1.4.0 && \
|
||||
apk add --no-cache libusb-dev
|
||||
#apt-get update && apt-get install -y libusb-1.0.0-dev && apt-get clean
|
||||
voluptuous==0.11.5
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
import noolite
|
||||
|
||||
class Noolite(hass.Hass):
|
||||
noolite = noolite.NooLite()
|
||||
brightness = 25
|
||||
force = False
|
||||
channel = 0
|
||||
|
||||
def initialize(self):
|
||||
self.run_at_sunrise(self.sunrise_cb)
|
||||
@@ -25,11 +22,11 @@ class Noolite(hass.Hass):
|
||||
|
||||
def noolite_off(self):
|
||||
self.log("Turning off salt lamp.")
|
||||
self.noolite.off(self.channel)
|
||||
self.turn_off(self.args['entity_id'])
|
||||
|
||||
def noolite_on(self, brightness=120):
|
||||
self.log("Turning on salt lamp for brightness {}.".format(brightness))
|
||||
self.noolite.set(self.channel, brightness)
|
||||
self.turn_on(self.args['entity_id'], brightness=self.brightness)
|
||||
|
||||
def sunset_cb(self, kwargs):
|
||||
self.noolite_on(self.brightness)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
salt_lamp:
|
||||
module: salt_lamp
|
||||
class: Noolite
|
||||
class: Noolite
|
||||
entity_id: light.salt_lamp
|
||||
@@ -4,6 +4,7 @@
|
||||
watchdog_sensor_power_active_power:
|
||||
class: Watchdog
|
||||
module: watchdog
|
||||
constraint: input_boolean.watchdog_report
|
||||
entity: sensor.power_active_power
|
||||
check_interval: 60
|
||||
timeout: 360
|
||||
@@ -16,6 +17,7 @@ watchdog_sensor_power_active_power:
|
||||
watchdog_wemos_uptime:
|
||||
class: Watchdog
|
||||
module: watchdog
|
||||
constraint: input_boolean.watchdog_report
|
||||
entities:
|
||||
- sensor.uptime_airfresher
|
||||
- sensor.uptime_bath
|
||||
@@ -30,6 +32,7 @@ watchdog_wemos_uptime:
|
||||
watchdog_sonoff_uptime:
|
||||
class: Watchdog
|
||||
module: watchdog
|
||||
constraint: input_boolean.watchdog_report
|
||||
entities:
|
||||
- sensor.uptime_bathlight
|
||||
- sensor.uptime_kitchen
|
||||
|
||||
@@ -26,4 +26,4 @@ class HomekitPresense(hass.Hass):
|
||||
elif new == "off" and old == "on":
|
||||
self.fire_event(self.args['leave_event'])
|
||||
self.log("{} turned {}".format(entity, new))
|
||||
self.notify("{} turned {}".format(entity, new), name = self.args['notify'])
|
||||
#self.notify("{} turned {}".format(entity, new), name = self.args['notify'])
|
||||
@@ -32,25 +32,32 @@ class WorkTime(hass.Hass):
|
||||
self.listen_event(self.leave_event, self.args['leave_event'])
|
||||
self.run_daily(self.reset_timer_tick, self.parse_time("23:59:59"))
|
||||
self.load_state()
|
||||
self.arrive_event(None, None, None)
|
||||
#self.save_state()
|
||||
self.run_timer()
|
||||
|
||||
def arrive_event(self, event_id, event_args, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
if self.arrive_time != None:
|
||||
self.log('You have already arrived to the work today at {}'.format(self.arrive_time))
|
||||
self.run_timer()
|
||||
return
|
||||
|
||||
self.arrive_time = self.datetime()
|
||||
self.leave_time = self.datetime()+datetime.timedelta(hours=self.work_hours)
|
||||
self.notify_time = self.leave_time-datetime.timedelta(minutes=self.notify_before_leave_in_minutes)
|
||||
if self.notify_time<self.datetime():
|
||||
self.notify_time=self.datetime()+datetime.timedelta(seconds=self.notify_every_seconds)
|
||||
self.save_state()
|
||||
self.run_timer()
|
||||
self.log("Monster has arrived to work at {}, work till {}, will notify at {}.".format(self.arrive_time, self.leave_time, self.notify_time))
|
||||
self.timers.append(self.run_every(self.timer_tick, self.notify_time, self.notify_every_seconds))
|
||||
self.notify("Добро пожаловать в офис. Сегодня работаешь до {}.".format(self.format_time(self.leave_time)), name = self.args['notify'])
|
||||
|
||||
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))
|
||||
|
||||
def leave_event(self, event_id, event_args, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
@@ -73,9 +80,10 @@ class WorkTime(hass.Hass):
|
||||
self.notify(message, name = self.args['notify'])
|
||||
|
||||
def timer_tick(self, args) -> None:
|
||||
self.log('timer tick')
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
if self.datetime()<self.leave_time:
|
||||
if self.datetime()<self.notify_time:
|
||||
return
|
||||
message = "Ты пришел на работу в {}, работаешь до {}. Пора домой!".format(self.format_time(self.arrive_time), self.format_time(self.leave_time))
|
||||
self.notify(message, name = self.args['notify'])
|
||||
@@ -86,6 +94,7 @@ class WorkTime(hass.Hass):
|
||||
self.timers = []
|
||||
|
||||
def reset_timer_tick(self, kwargs):
|
||||
self.log("Resetting timer.")
|
||||
self.arrive_time = None
|
||||
self.leave_time = None
|
||||
self.notify_time = None
|
||||
|
||||
+12
-3
@@ -8,6 +8,18 @@ services:
|
||||
- "1883:1883"
|
||||
restart: always
|
||||
|
||||
noolite:
|
||||
build: ./noolite/
|
||||
container_name: noolite
|
||||
privileged: true
|
||||
depends_on:
|
||||
- mosquitto
|
||||
env_file: ./mosquitto/settings/mqtt.env
|
||||
environment:
|
||||
- MQTT_SERVER=mosquitto
|
||||
- TOPIC=home
|
||||
- CHANNELS=1
|
||||
|
||||
mysql:
|
||||
image: mariadb
|
||||
container_name: mysql
|
||||
@@ -50,9 +62,6 @@ services:
|
||||
container_name: appdaemon
|
||||
depends_on:
|
||||
- hass
|
||||
privileged: true
|
||||
devices:
|
||||
- /dev/bus/usb:/dev/bus/usb
|
||||
volumes:
|
||||
- ./appdaemon/settings:/conf
|
||||
- ./hass/settings/secrets.yaml:/conf/secrets.yaml:ro
|
||||
|
||||
@@ -47,3 +47,8 @@ lock_report:
|
||||
name: Отчет замка
|
||||
icon: mdi:lock-alert
|
||||
initial: on
|
||||
|
||||
watchdog_report:
|
||||
name: Отчет watchdog
|
||||
icon: mdi:lock-alert
|
||||
initial: on
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
# - platform: noolite
|
||||
# tx_channel: 1
|
||||
# friendly_name: "salt_lamp"
|
||||
# dimmable: true
|
||||
- platform: mqtt
|
||||
name: "salt_lamp"
|
||||
availability_topic: "home/noolite/$online"
|
||||
payload_available: "true"
|
||||
payload_not_available: "false"
|
||||
state_topic: "home/noolite/ch0/power"
|
||||
command_topic: "home/noolite/ch0/power/set"
|
||||
payload_on: "on"
|
||||
payload_off: "off"
|
||||
brightness_state_topic: "home/noolite/ch0/brightness"
|
||||
brightness_command_topic: "home/noolite/ch0/brightness/set"
|
||||
brightness_scale: 120
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
- platform: cert_expiry
|
||||
- platform: cert_expiry
|
||||
host: !secret base_host
|
||||
@@ -28,7 +28,7 @@ views:
|
||||
- light.yeelight_mono1_34ce0087ff33
|
||||
- light.yeelight_mono1_f0b4290e5444
|
||||
- light.yeelight_mono1_f0b429a8f6df
|
||||
# - light.salt_lamp
|
||||
- light.salt_lamp
|
||||
- cover.curtain_158d0002b0c46a
|
||||
- switch.plug_158d0001104a0c
|
||||
- switch.plug_158d00010dd98d
|
||||
@@ -347,6 +347,7 @@ views:
|
||||
- input_boolean.water_counters_report
|
||||
- input_boolean.work_presence_report
|
||||
- input_boolean.lock_report
|
||||
- input_boolean.watchdog_report
|
||||
- type: entities
|
||||
title: "Метки"
|
||||
show_header_toggle: true
|
||||
@@ -378,7 +379,7 @@ views:
|
||||
- sensor.memory_free
|
||||
- sensor.swap_use_percent
|
||||
- sensor.disk_use_percent
|
||||
- sensor.ssl_certificate_expiry
|
||||
- sensor.ssl_certificate_expiry_2
|
||||
- type: entities
|
||||
title: "Сеть"
|
||||
show_header_toggle: false
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM python:latest
|
||||
|
||||
RUN pip3 install homie noolite && \
|
||||
apt-get update && apt-get install -y libusb-1.0.0-dev && apt-get clean
|
||||
ADD noolitemqtt.py /noolitemqtt.py
|
||||
|
||||
CMD python3 /noolitemqtt.py
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
import time
|
||||
import homie
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import noolite
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
config = {
|
||||
"HOST": os.environ.get('MQTT_SERVER', 'mosquitto'),
|
||||
"PORT": os.environ.get('MQTT_PORT', 1883),
|
||||
"KEEPALIVE": 10,
|
||||
"USERNAME": os.environ.get('USERNAME', ''),
|
||||
"PASSWORD": os.environ.get('PASS', ''),
|
||||
"CA_CERTS": os.environ.get('CA_CERTS', ''),
|
||||
"DEVICE_ID": os.environ.get('DEVICE_ID', 'noolite'),
|
||||
"DEVICE_NAME": os.environ.get('DEVICE_NAME', 'noolite'),
|
||||
"TOPIC": os.environ.get('TOPIC', 'homie'),
|
||||
"CHANNELS": os.environ.get('CHANNELS', 16)
|
||||
}
|
||||
|
||||
Homie = homie.Homie(config)
|
||||
nodes = {}
|
||||
n = noolite.NooLite()
|
||||
|
||||
def brightnessHandler(mqttc, obj, msg):
|
||||
try:
|
||||
payload = msg.payload.decode("UTF-8").lower()
|
||||
topic = msg.topic
|
||||
channel = parse_channel(topic)
|
||||
logger.info("payload: {}, topic: {}, channel: {}".format(payload, topic, channel))
|
||||
if channel not in nodes:
|
||||
logger.error("Cannot find channel {}".format(channel))
|
||||
return true
|
||||
if not payload.isdigit():
|
||||
logger.error("Invalid payload {}".format(payload))
|
||||
return
|
||||
node = nodes[channel]
|
||||
brightness = int(payload)
|
||||
ch_num = int(channel.replace('ch',''))
|
||||
logger.info("[{}] brightness: {}".format(channel, brightness))
|
||||
n.set(ch_num, brightness)
|
||||
node.setProperty("brightness").send(brightness)
|
||||
except Exception as e:
|
||||
logger.error("Something gone wrong in brightnessHandler: {}!".format(e))
|
||||
|
||||
def powerHandler(mqttc, obj, msg):
|
||||
try:
|
||||
payload = msg.payload.decode("UTF-8").lower()
|
||||
topic = msg.topic
|
||||
channel = parse_channel(topic)
|
||||
logger.info("payload: {}, topic: {}, channel: {}".format(payload, topic, channel))
|
||||
if channel not in nodes:
|
||||
logger.error("Cannot find channel {}".format(channel))
|
||||
return true
|
||||
node = nodes[channel]
|
||||
ch_num = int(channel.replace('ch',''))
|
||||
if payload == 'on' or payload == 'true':
|
||||
logger.info("[{}] Power: on".format(channel))
|
||||
n.on(ch_num)
|
||||
node.setProperty("power").send("on")
|
||||
else:
|
||||
logger.info("[{}] Power: off".format(channel))
|
||||
n.off(ch_num)
|
||||
node.setProperty("power").send("off")
|
||||
except Exception as e:
|
||||
logger.error("Something gone wrong in powerHandler: {}!".format(e))
|
||||
|
||||
def parse_channel(topic):
|
||||
found = re.findall('(ch\d+)', topic)
|
||||
if len(found) == 0:
|
||||
return "";
|
||||
return found[0]
|
||||
|
||||
def main():
|
||||
logger.info("Config: {}".format(config))
|
||||
Homie.setFirmware("noolite-gateway", "1.0.0")
|
||||
channels = int(config['CHANNELS'])
|
||||
for i in range(0, channels):
|
||||
nodeName = "ch{}".format(i)
|
||||
node = Homie.Node(nodeName, nodeName)
|
||||
node.advertise("power").settable(powerHandler)
|
||||
node.advertise("brightness").settable(brightnessHandler)
|
||||
#node.advertise("bind").settable(switchOnHandler)
|
||||
nodes[nodeName]=node
|
||||
|
||||
Homie.setup()
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
logger.info("Quitting.")
|
||||
Reference in New Issue
Block a user