Flow Details
π Activation and Timing:
- The script is marked as active by setting
active = true
. - It runs every minute as specified in the trigger section
timer = {'every 1 minutes'}
to ensure frequent updates.
-
π Logging:
- Entries are logged with the marker "AWTRIX_APP", making it easy to filter and identify messages related to this script.
- The logging level is set to
domoticz.LOG_INFO
, capturing detailed informational logs for monitoring and debugging.
-
π Power Check:
- Checks if the "AWTRIX3 - Power" device is "On" before proceeding. If not, the script execution is halted.
- Logs if the power device is off to explain why the script is not executing the status updates.
-
π Device Status Collection:
- Iterates over a predefined list of devices in
orderedDevices
to ensure a consistent sequence. - Retrieves status for each device based on its type and applies the corresponding data formatting:
- Temperature π‘οΈ: Captures temperature in Celsius (e.g., "21.5C").
- Power β‘: Records current power usage in watts (e.g., "150W").
- Water π§: Gathers water usage in liters (e.g., "23.4L").
- Text π: Fetches textual status (e.g., "Online").
- Switch π: Monitors switch state, "On" or "Off".
- Selector π: Retrieves the current selector level name (e.g., "High").
- Gas π: Measures gas usage in cubic meters (e.g., "12.34 mΒ³").
- Logs successfully gathered statuses and any missing data errors.
- Iterates over a predefined list of devices in
-
π€ Status Transmission to AWTRIX:
- Converts collected status data into JSON format for transmission to AWTRIX.
- Accesses the "AWTRIX3 - Send Custom App" device to send updates.
- Activates the app device briefly to ensure data is sent, logging the transmission for confirmation.
π Purpose: This script facilitates real-time status monitoring from various home automation devices by displaying dynamic updates on the AWTRIX, enhancing the integration of Domoticz and AWTRIX for a seamless smart home experience.
More Information:
Domoticz:
www.domoticz.com
Domoticz AWTRIX3 Plugin:
https://github.com/galadril/Domoticz-AWTRIX3-Plugin
return {
-- The script is active
active = true,
-- Trigger section: run the script every 1 minute
on = {
timer = {
'every 1 minutes'
}
},
-- Custom logging level for this script
logging = {
level = domoticz.LOG_INFO,
marker = "AWTRIX_APP"
},
-- Persistent variables to track rotation for singleApp mode
data = {
currentIndex = { initial = 0 } -- Start with the first status
},
-- Event execution when the timer triggers the script
execute = function(domoticz)
-- Ordered list of device names to enforce consistent iteration
local orderedDevices = {
"ChristmasTree",
"Temperature - Room1",
"Power",
"Water - Total usage",
"Ventilation",
"Heatpump - Status",
"Temperature - Outside",
"Gas"
}
-- Unified dictionary of devices with icon mappings
local devicesConfig = {
["ChristmasTree"] = { icon = 4889, type = "switch" },
["Temperature - Room1"] = { icon = 2355, type = "temperature" },
["Power"] = { icon = 95, type = "power" },
["Water - Total usage"] = { icon = 18191, type = "water" },
["Ventilation"] = { icon = 20121, type = "selector" },
["Heatpump - Status"] = { icon = 7627, type = "text" },
["Temperature - Outside"] = { icon = 64162, type = "temperature" },
["Gas"] = { icon = 54633, type = "gas" }
}
-- Check if the "AWTRIX3 - Power" device is on
local powerDevice = domoticz.devices("AWTRIX3 - Power")
if not powerDevice or powerDevice.state ~= "On" then
domoticz.log("AWTRIX3 - Power device is off. Skipping status updates.", domoticz.LOG_INFO)
return
else
domoticz.log("AWTRIX3 - Power device is on. Proceeding with status updates.", domoticz.LOG_INFO)
end
local statuses = {}
-- Function to generate JSON description ({"text": "status", "icon": icon})
local function getDescription(device, config)
local status = ""
local icon = config.icon
-- Check for different device types and retrieve the appropriate value
if config.type == "temperature" and device.temperature then
status = string.format("%.1fC", device.temperature)
elseif config.type == "power" and device.usage then
status = string.format("%dW", device.usage)
elseif config.type == "water" and device.counterToday then
status = string.format("%.1fL", device.counterToday)
elseif config.type == "text" and device.text then
status = device.text
elseif config.type == "switch" then
status = device.state
elseif config.type == "selector" then
status = device.levelName
elseif config.type == "gas" and device.counterToday then
status = string.format("%.2f m3", device.counterToday)
end
-- Return the formatted JSON description if status is not empty
if status ~= "" then
return { text = status, icon = icon }
end
return nil
end
-- Collect statuses for each relevant device in a fixed order
for _, deviceName in ipairs(orderedDevices) do
local config = devicesConfig[deviceName]
local device = domoticz.devices(deviceName)
if device then
local description = getDescription(device, config)
if description then
table.insert(statuses, description)
domoticz.log(string.format("Collected status for %s: %s", deviceName, domoticz.utils.toJSON(description)), domoticz.LOG_DEBUG)
else
domoticz.log(string.format("No status collected for %s", deviceName), domoticz.LOG_INFO)
end
else
domoticz.log("Device not found in Domoticz: " .. deviceName, domoticz.LOG_ERROR)
end
end
-- Ensure we have statuses collected
if #statuses == 0 then
domoticz.log("No statuses available to send to AWTRIX.", domoticz.LOG_ERROR)
return
end
-- MultiApp: Send all statuses as an array
local statusesJSON = domoticz.utils.toJSON(statuses)
domoticz.log("Sending statuses to AWTRIX (multiApp): " .. statusesJSON, domoticz.LOG_INFO)
local appDevice = domoticz.devices('AWTRIX3 - Send Custom App')
if appDevice then
appDevice.setDescription(statusesJSON)
appDevice.switchOn().afterSec(2)
else
domoticz.log("AWTRIX3 - Send Custom App device not found", domoticz.LOG_ERROR)
end
end
}
-- Flow first published on January 2, 2025.