From f8c1b116a87994f37e85052f679b8347f0b7a490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Julian-Steffen=20M=C3=BCller?= Date: Wed, 25 Nov 2020 23:21:43 +0100 Subject: [PATCH] - --- AlexaTVConverter.lua | 2 ++ TV_AVR_Input_Merge.lua | 49 +++++++++++++++++++++++++++++++++++++++ Weihnachtsbeleuchtung.lua | 26 +++++++++++++++++++++ db_logger.lua | 47 +++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 TV_AVR_Input_Merge.lua create mode 100644 Weihnachtsbeleuchtung.lua create mode 100644 db_logger.lua diff --git a/AlexaTVConverter.lua b/AlexaTVConverter.lua index 28fe8ef..a517e1b 100644 --- a/AlexaTVConverter.lua +++ b/AlexaTVConverter.lua @@ -1,4 +1,6 @@ SERVICE_NAME = "AlexaTVConverter" +SERVICE_VERSION = "1.0.0" + TOPIC_SOURCE = "wohnzimmer/tv/alexainput/set"; TOPIC_TV_INPUT = ""; diff --git a/TV_AVR_Input_Merge.lua b/TV_AVR_Input_Merge.lua new file mode 100644 index 0000000..cd12e97 --- /dev/null +++ b/TV_AVR_Input_Merge.lua @@ -0,0 +1,49 @@ +SERVICE_NAME = "LGTV & Denon AVR input merge" +SERVICE_VERSION = "1.0.0" + +TOPIC_TV_INPUT = "wohnzimmer/tv/input"; +TOPIC_SOURCE = "wohnzimmer/tv/input/set"; + +TOPIC_LGTV_INPUT = "wohnzimmer/lgtv/input"; +TOPIC_AVR_INPUT = "wohnzimmer/avr/input"; +TOPIC_LGTV_INPUT_SET = "wohnzimmer/lgtv/input/set"; +TOPIC_AVR_INPUT_SET = "wohnzimmer/avr/input/set"; + +AVR_INPUT_ON_TV = "hdmi3" +AVR_INPUTS = {"playstation", "xbox", "nintendo", "appletv", "wiiu"} + +function thrawn_on_start() + thrawn_register_service(SERVICE_NAME) + + thrawn_log("Starting LUA Service " .. SERVICE_NAME) + + + thrawn_subscribe(TOPIC_SOURCE) +end + +function is_avr_input(input) + for _, avr_input in ipairs(AVR_INPUTS) do + if input == avr_input then + return true + end + end + + return false +end + +function thrawn_on_update(state) + thrawn_log("RECV: " .. state.value .. " ON TOPIC " .. state.topic) + + if state.topic == TOPIC_SOURCE then + if is_avr_input(state.value) then + thrawn_publish(thrawn_create_topic_state(TOPIC_LGTV_INPUT_SET, AVR_INPUT_ON_TV)) + thrawn_publish(thrawn_create_topic_state(TOPIC_AVR_INPUT_SET, state.value)) + end + elseif state.topic == TOPIC_LGTV_INPUT or TOPIC_AVR_INPUT then + if TOPIC_LGTV_INPUT == AVR_INPUT_ON_TV then + thrawn_publish(thrawn_create_topic_state(TOPIC_TV_INPUT, thrawn_cached_topic(TOPIC_AVR_INPUT))) + else + thrawn_publish(thrawn_create_topic_state(TOPIC_TV_INPUT, thrawn_cached_topic(TOPIC_LGTV_INPUT))) + end + end +end \ No newline at end of file diff --git a/Weihnachtsbeleuchtung.lua b/Weihnachtsbeleuchtung.lua new file mode 100644 index 0000000..f8abc9d --- /dev/null +++ b/Weihnachtsbeleuchtung.lua @@ -0,0 +1,26 @@ +SERVICE_NAME = "Weihnachtsbeleuchtung" +SERVICE_VERSION = "1.0.0" + +function thrawn_on_start() + thrawn_register_service(SERVICE_NAME) + + thrawn_log("Starting LUA Service " .. SERVICE_NAME) + + thrawn_schedule("0 00 01 * * *", "on_deactivate") + thrawn_schedule("0 00 16 * * *", "on_activtate") + + thrawn_schedule("0 00 06 * * *", "on_activtate") + thrawn_schedule("0 00 10 * * *", "on_deactivate") + +end + +function thrawn_on_update(state) +end + +function on_activtate(time) + thrawn_publish("kueche/lights/girlande/on", "1") +end + +function on_deactivate(time) + thrawn_publish("kueche/lights/girlande/on", "0") +end \ No newline at end of file diff --git a/db_logger.lua b/db_logger.lua new file mode 100644 index 0000000..08e1a67 --- /dev/null +++ b/db_logger.lua @@ -0,0 +1,47 @@ +SERVICE_NAME = "DB Logger" +SERVICE_VERSION = "1.0.0" + +function thrawn_on_start() + thrawn_register_service(SERVICE_NAME) + + thrawn_log("Starting LUA Service " .. SERVICE_NAME) + + --room/type/device_name/state_name + --example: + --wohnzimmer/lights/eckstehlampe01/on + --kueche/sensors/kuehlschrank_tuer/open + thrawn_subscribe("+/lights/+/on") + thrawn_subscribe("+/lights/+/brightness") + thrawn_subscribe("+/lights/+/color_temp") +end + +function thrawn_on_update(state) + thrawn_log("RECV: " .. state.value .. " ON TOPIC " .. state.topic) + + local topic_comp = thrawn_topic_components(state.topic) + + if #topic_comp == 4 and topic_comp[2] == "lights" then + log_light(topic_comp[1], topic_comp[3], topic_comp[4], state.value) + end +end + +function log_light(room, name, type, value) + local base_topic = room .. "/lights/" .. name + + local is_on = false + local is_on_cached = tonumber(thrawn_cached_topic(base_topic .. "/on")) + if is_on_cached ~= nil then + is_on = is_on_cached > 0 + end + + local brightness = tonumber(thrawn_cached_topic(base_topic .. "/brightness")) + local color_temp = tonumber(thrawn_cached_topic(base_topic .. "/color_temp")) + + if brightness ~= nil and color_temp ~= nil then + thrawn_log_light_tw(room, name, is_on, brightness, color_temp) + elseif brightness ~= nil and color_temp == nil then + thrawn_log_light_dimmable(room, name, is_on, brightness) + elseif brightness == nil and olor_temp == nil then + thrawn_log_light(room, name, is_on) + end +end \ No newline at end of file