Added discord logging
This commit is contained in:
parent
cc79c41d2f
commit
57ca8f542d
23
appdaemon/apps/logger.py
Normal file
23
appdaemon/apps/logger.py
Normal file
@ -0,0 +1,23 @@
|
||||
from base import Base
|
||||
|
||||
class Logger(Base):
|
||||
def initialize(self):
|
||||
super().initialize()
|
||||
|
||||
self.listen_event(self.event)
|
||||
self.listen_state(self.state)
|
||||
self.log_out("Appdaemon logger started")
|
||||
|
||||
def log_out(self, message):
|
||||
self.call_service('notify/discord_log', message=message)
|
||||
|
||||
def event(self, name, data, kwargs):
|
||||
if name == 'call_service' and data['service'] == 'discord_log':
|
||||
return
|
||||
self.log_out("EVENT: {} {}".format(name, data))
|
||||
|
||||
def state(self, entity, attribute, old, new, kwargs):
|
||||
tracked_domains = ['light', 'switch', 'device_tracker', 'binary_sensor']
|
||||
domain = entity.split('.')[0]
|
||||
if domain in tracked_domains:
|
||||
self.log_out("STATE: {} {} {} =>{}".format(entity, attribute, old, new))
|
5
appdaemon/apps/logger.yaml
Normal file
5
appdaemon/apps/logger.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
logger:
|
||||
module: logger
|
||||
class: Logger
|
||||
global_dependencies:
|
||||
- base
|
48
packages/logging.yaml
Normal file
48
packages/logging.yaml
Normal file
@ -0,0 +1,48 @@
|
||||
homeassistant:
|
||||
customize:
|
||||
package.node_anchors:
|
||||
common: &common
|
||||
package: "logging"
|
||||
|
||||
notify:
|
||||
- platform: rest
|
||||
name: discord_log
|
||||
method: POST
|
||||
message_param_name: content
|
||||
title_param_name: username
|
||||
data:
|
||||
username: Åvägen
|
||||
resource: !secret discord_log
|
||||
- platform: rest
|
||||
name: discord_info
|
||||
method: POST
|
||||
message_param_name: content
|
||||
title_param_name: username
|
||||
data:
|
||||
username: Åvägen
|
||||
resource: !secret discord_info
|
||||
|
||||
|
||||
script:
|
||||
log_message:
|
||||
sequence:
|
||||
- service: notify.discord_log
|
||||
data_template:
|
||||
message: "{{ message }}"
|
||||
info_message:
|
||||
sequence:
|
||||
- service: notify.discord_info
|
||||
data_template:
|
||||
message: "{{ message }}"
|
||||
- service: notify.discord_log
|
||||
data_template:
|
||||
message: "INFO: {{ message }}"
|
||||
|
||||
automation:
|
||||
trigger:
|
||||
platform: homeassistant
|
||||
event: start
|
||||
action:
|
||||
- service: script.info_message
|
||||
data:
|
||||
message: "Home Assistant started!"
|
Loading…
x
Reference in New Issue
Block a user