[LUA] Kontrolowanie poziomu głośności przez dowolne web api z poziomu domoticza

Znalazłem wczoraj prosty skrypt autorstwa C-Duv, który dostosowałem do potrzeb sterowania głośnością w dekoderze opartym o OpenWebif (Enigma2).

Skrypt powinien być wyzwalany zmianą stanu urządzenia, czyli w zapleczu domoticz wybierz wyzwalacz jako „Device”.

Urządzenie dodajemy przez: SPRZĘT –> Nowe wirtualne urządzenie –> Przełącznik.

Następnie edytujemy go w zakładce przełączniki, zmieniamy typ na DIMMER oraz ikonkę najlepiej na tą z głośniczkiem.

Możesz go w miarę łatwo dostosować do innego formatu api zmieniając „fullurl”

commandArray = {}

— Name of the dummy Domoticz dimmer:
DomDevice = 'GŁOŚNOŚĆ’

if devicechanged[DomDevice] then
–print(DomDevice..’ received order: ’..devicechanged[DomDevice]) — DEBUG:

if string.match(devicechanged[DomDevice], 'Set Level: ’) then — „Set Level: 42 %” type of order
print(DomDevice..’ level changed (’..otherdevices_svalues[DomDevice]..’)’) — DEBUG:

— Compute the volume: Use the „Set Level: 42 %” order and strip anything that’s not a digit
volume = devicechanged[DomDevice]:gsub(’%D’, ”)
volumestr = tonumber(volume)
fullurl = 'http://[IP_OPENWEBIF]/web/vol?set=set’ .. volumestr
print(’adres: ’ .. fullurl)
— Supports level=0 (even though Domoticz seems to handle it: Setting device’s level/slider to „0”, sets device to „Off”)
commandArray[’OpenURL’]= fullurl
end
end

return commandArray

 

Mój skrypt na github: https://github.com/marcinprzybysz86/domoticz/blob/master/volume_slider.lua

źródło oryginalnego skryptu: https://gist.github.com/C-Duv/03de85cafc2cd2324e9d856d5889e5cb

Facebook - komentarze