Die Ansteuerung von Homematic Gerät mit DomoticZ ist nicht immer trivial. Anbei ein LUA Script zur Ansteuerung von Homematic Jalousien über eine CCU mit installierter XML_API.
Das komplette Setup ist in diesem TecFacts Artikel beschrieben.
--###################################################################
--#Script Name : homematic_blinds.lua
--#Description : Script to operate blinds on Homematic CCU
--# based on a inverted DomoticZ Blind Slider device
--#Args : needs 2 User Variables : CCU_IP and HMBlinds
--#Date : 03. February 2019
--#Author : Heiko Zschenderlein
--#Email : Diese E-Mail-Adresse ist vor Spambots geschützt! Zur Anzeige muss JavaScript eingeschaltet sein!
--#Comments : Development State, to be improved
--#Disclaimer : Please read the Disclaimer at the end of the script
--# : Bitte lesen Sie den Haftungsausschluss am Ende des Scripts
--###################################################################
commandArray = {}
--Uservariables to String VAriable
CCU_IP = uservariables["CCU_IP"]
UserVar = uservariables["HMBlinds"]
-- Array to store identifier pairs
parameterA = {}
-- create array from user string variable
for k, v in string.gmatch(UserVar,"(%w+):(%w+)") do
parameterA[tonumber(k)] = tonumber(v)
end
-- function to read xmlAPI output from CCU
function XML_Capture(cmd,flatten)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if flatten then
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
end
return s
end
-- function to update local device values
local function update(idx, value1)
local cmd = string.format("%d|2|%d", idx, value1)
table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
-- function to round numbers
function round(number, decimals)
local power = 10^decimals
return math.floor(number * power) / power
end
-- loop through array, get current status from Homematic CCU and update devices in DomoticZ accordingly
for dom_idx,hm_idx in pairs(parameterA) do
XML_string=XML_Capture("curl -s 'http://"..CCU_IP.."/addons/xmlapi/state.cgi?datapoint_id="..hm_idx.."'",1)
valid = string.find(XML_string, "<state>") -- check we are looking in the right place
if valid == nil then
print ("Bad XML status read - info NOT updated")
else
level = round(tonumber(string.sub(XML_string,string.find(XML_string,"value=")+7,string.find(XML_string,"value=")+11)) * 100,0)
update(tonumber(dom_idx),tonumber(level))
end
end
-- function to control Homematic Devices
for deviceName,deviceValue in pairs(devicechanged) do
for dom_idx,hm_idx in pairs(parameterA) do
if (otherdevices_idx[deviceName] == dom_idx) then
if deviceValue == "Open" then
commandstring = 'curl -s "http://'..CCU_IP..'/addons/xmlapi/statechange.cgi?ise_id='..hm_idx..'&new_value=1"'
elseif deviceValue == "Closed" then
commandstring = 'curl -s "http://'..CCU_IP..'/addons/xmlapi/statechange.cgi?ise_id='..hm_idx..'&new_value=0"'
else
level= otherdevices_svalues[deviceName]/100
commandstring = 'curl -s "http://'..CCU_IP..'/addons/xmlapi/statechange.cgi?ise_id='..hm_idx..'&new_value='..level..'"'
end
-- print(commandstring)
os.execute(commandstring)
end
end
end
return commandArray
--# DISCLAIMER :
--# Downloading and using data from this website occurs at the own risk of the User. The Provider does not accept any liability for damages that occur directly or indirectly through the use of provided data.
--# All logos, trademarks and word marks used, even if not expressly marked as such, are the property of their respective owners.
--# Das Herunterladen und Verwenden von Daten von dieser Website erfolgt auf eigenes Risiko des Benutzers. Der Anbieter übernimmt keine Haftung für Schäden, die direkt oder indirekt durch die Verwendung der bereitgestellten Daten entstehen.
--# Alle verwendeten Logos, Markenzeichen und Wortmarken sind, auch wenn nicht ausdrücklich als solche gekennzeichnet, Eigentum ihrer jeweiligen Inhaber.