This commit is contained in:
2020-11-25 23:21:43 +01:00
parent a9021604a2
commit f8c1b116a8
4 changed files with 124 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
SERVICE_NAME = "AlexaTVConverter"
SERVICE_VERSION = "1.0.0"
TOPIC_SOURCE = "wohnzimmer/tv/alexainput/set";
TOPIC_TV_INPUT = "";

49
TV_AVR_Input_Merge.lua Normal file
View File

@@ -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

26
Weihnachtsbeleuchtung.lua Normal file
View File

@@ -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

47
db_logger.lua Normal file
View File

@@ -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