Powiadomienia
Wyczyść wszystko

Pomoc httpResponse

19 Wpisów
3 Użytkownicy
1 Likes
1,063 Wyświetleń
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

Obecnie jest tak, że Motionsensor (zeegbee) po wykryciu ruchu uruchamia ustawioną w nim akcję script:///home/pi/domoticz/scripts/display.sh KOT buszuje w garazu !!!

Tekst wyświetla się na TV. Gdy Tv wyłączony to generuje to błąd w logach Error: Error executing script command (/home/pi/domoticz/scripts/display.sh). returned: 34304

Pomysł więc jest taki, żeby jak TV nie załączone to niech nie wykonuje scriptu. Chciałem więc posłużyć się lua aby to usprawnić ale nie potrafię tego prawidłowo napisać mimo prób. Warunki czasowe ogarniam ale nie mogę dostać httpResponse post data., jedynie udało mi się prawidłowo uzyskać GET:

{
on =
{
timer = {'every minute'},
httpResponses = { 'mycallbackstring' },
},

logging = { level = domoticz.LOG_DEBUG, marker = 'post data' },

execute = function(dz, item)

local targetIP = '192.168.1.4' -- to IP mojego TV

local function setVolume(volume)
url = 'http://' .. targetIP .. ':1925/1/audio/volume'
dz.openURL(
{
url = url,
method = 'POST',
callback = 'mycallbackstring',
postData =
{
muted = false,
current = volume,
}
})
end

if item.isTimer then
setVolume(40)

end
end
}

 

 

 

Jak użyję przeglądarki to po wpisaniu 

pytanie http://192.168.1.4:1925/1/audio/volume
zwróci

{
"muted": false,
"current": 40,
"min": 0,
"max": 60
}
 
Dodane : 14/04/2022 2:48 pm
(@steel_rat)
Wpisów: 603
Ekspert
 

Można by np. zainstalować plugin System Alive Checker. Działa on na zasadzie ping. Podać IP tv do niego wstawić kontrolkę w Domoticzu dla tego Pinga. Jak telewizor odpowiada na ping to dopiero wysyłać powiadomienie.

 
Dodane : 14/04/2022 6:10 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

@steel_rat Można i tak. Bardziej chodziło mi o rozbudowanie tego co już skleciłem  o warunek obecności TV  i oczywiście zakres czasu w którym będzie działał, ale utknąłem:

return {
on = {
devices = {
'TekstTV', -- nazwa wlacznik w domoticz
'GarażR' -- nazwa czujnika w domoticz
}
},
data =
{
warunek = { initial = false },
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'PIR Garaż',
},
execute = function(dz, item)

local motion = dz.devices('GarażR') -- nazwa czujnika
local switch = dz.devices('TekstTV') -- nazwa włacznika

if item == motion then -- detekcja aktywna
if motion.active and not switch.active then -- detekcja wyzwala skrypt
dz.data.warunek = true
switch.cancelQueuedCommands()
switch.switchOn().checkFirst()
elseif motion.active and switch.active and dz.data.warunek == true then
switch.cancelQueuedCommands()
elseif not motion.active and dz.data.warunek == true then
switch.switchOff().checkFirst()
end
elseif item == switch and item.active and not motion.active then
dz.data.warunek = false
end
end
}
 
Dodane : 14/04/2022 8:44 pm
(@steel_rat)
Wpisów: 603
Ekspert
 

A coś takiego

return {
on = {
devices = {
'GarażR' -- nazwa czujnika w domoticz
'TekstTV', -- nazwa wlacznik w domoticz
}
},
data =
{
warunek = { initial = false },
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'PIR Garaż',
},
execute = function(dz, item)

local motion = dz.devices('GarażR') -- nazwa czujnika
local switch = dz.devices('TekstTV') -- nazwa włacznika
local tvon = dz.devices('Telewizor') -- nazwa tv
if tvon.active then
        if item == motion then
	        if motion.active and not switch.active and then -- detekcja wyzwala skrypt
		           dz.data.warunek = true
		            switch.cancelQueuedCommands()
		            switch.switchOn().checkFirst()
	        elseif 	motion.active and switch.active and dz.data.warunek == true then
		      switch.cancelQueuedCommands()
	        elseif not motion.active and dz.data.warunek == true then
		       switch.switchOff().checkFirst()
                end
	elseif item == switch and item.active and not motion.active then
		dz.data.warunek = false
	end
end

}
 
Dodane : 14/04/2022 9:25 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

@steel_rat  czy tu :

local tvon = dz.devices('Telewizor') -- nazwa tv

chodzi o ping ustawiony jako contact ?

 
Dodane : 14/04/2022 9:32 pm
isom
 isom
(@isom)
Wpisów: 5079
Szef wszystkich szefów Moderator Zasłużony dla Forum, Donator 2K19, Donator 2K20
 

@mariusz-2 trudno pojąć co chcesz uzyskać z tego powyżej . Może troszkę wyjaśnienia , użycie w skrypcie 

switch.cancelQueuedCommands()

pozwala anulować polecenie, które ma się wykonać po określonym czasie , np mamy lampę i PIR , naruszenie PIR ma włączyć lampę na 10 sek , żeby zapobiec wyłączeniu tej lampy ( jeśli w tym czasie znów zostanie naruszony PIR) można właśnie użyć cancelQueuedCommands

Przykład 

if item == motion then
                if switch.active and motion.active then 
                      switch.cancelQueuedCommands()
                        switch.switchOff().afterSec(10).silent().checkFirst()
                    end

 Działa to tak :

Jak PIR jest aktywny i lampa świeci to anuluj wyłączenie lampy po 10 sek , ale jeśli lampa świeci i nie ma ruchu to nic nie anuluj tylko wyłącz lampę po 10 sek . 

Teraz co niby ma się zrobić w tym fragmencie kodu ?

elseif motion.active and switch.active and dz.data.warunek == true then
switch.cancelQueuedCommands()
elseif not motion.active and dz.data.warunek == true then
switch.switchOff().checkFirst()

Jeśli PIR aktywny i przełącznik aktywny  to anuluj co ? 

 

 
Dodane : 14/04/2022 9:38 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

Zrobiłem tak : 

on = {
devices = {
'TekstTV', -- nazwa wlacznik w domoticz tu mam podpiętą akcję włącz : script:///home/pi/domoticz/scripts/display.sh
'GarażR' -- nazwa czujnika w domoticz motion sensor

'TVPhilips' -- nazwa ping
}
},
data =
{
warunek = { initial = false },
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'PIR Garaż',
},
execute = function(dz, item)

local motion = dz.devices('GarażR') -- nazwa czujnika
local switch = dz.devices('TekstTV') -- nazwa włacznika
local motion = dz.devices('TVPhilips) -- nazwa ping (ustawiony jako motion sensor)

if item == motion then -- detekcja aktywna
if motion.active and not switch.active then -- detekcja wyzwala skrypt
dz.data.warunek = true
switch.cancelQueuedCommands()
switch.switchOn().checkFirst()
elseif motion.active and switch.active and dz.data.warunek == true then
switch.cancelQueuedCommands()
elseif not motion.active and dz.data.warunek == true then
switch.switchOff().checkFirst()
end
elseif item == switch and item.active and not motion.active then
dz.data.warunek = false
end
end
}

 

 

 
Dodane : 14/04/2022 9:40 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

@isom Chcę zrobić tak że PIR aktywny i TV aktywny włącz akcję .

 
Dodane : 14/04/2022 9:44 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 
Dodane przez: @isom

@mariusz-2 trudno pojąć co chcesz uzyskać z tego powyżej . Może troszkę wyjaśnienia , użycie w skrypcie 

switch.cancelQueuedCommands()

pozwala anulować polecenie, które ma się wykonać po określonym czasie , np mamy lampę i PIR , naruszenie PIR ma włączyć lampę na 10 sek , żeby zapobiec wyłączeniu tej lampy ( jeśli w tym czasie znów zostanie naruszony PIR) można właśnie użyć cancelQueuedCommands

Przykład 

if item == motion then
                if switch.active and motion.active then 
                      switch.cancelQueuedCommands()
                        switch.switchOff().afterSec(10).silent().checkFirst()
                    end

 Działa to tak :

Jak PIR jest aktywny i lampa świeci to anuluj wyłączenie lampy po 10 sek , ale jeśli lampa świeci i nie ma ruchu to nic nie anuluj tylko wyłącz lampę po 10 sek . 

Teraz co niby ma się zrobić w tym fragmencie kodu ?

elseif motion.active and switch.active and dz.data.warunek == true then
switch.cancelQueuedCommands()
elseif not motion.active and dz.data.warunek == true then
switch.switchOff().checkFirst()

Jeśli PIR aktywny i przełącznik aktywny  to anuluj co ? 

 

Teraz jest jasne użycie cancelQueuedCommands

 
Dodane : 14/04/2022 9:48 pm
(@steel_rat)
Wpisów: 603
Ekspert
 

Mi to znowu coś takiego wychodzi

on = {
devices = {
'GarażR' -- nazwa czujnika w domoticz motion sensor
'TVPhilips'
}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'PIR Garaż',
},
execute = function(dz, item)

local motion = dz.devices('GarażR') -- nazwa czujnika
local switch = dz.devices('TekstTV') -- nazwa włacznika
local motion1 = dz.devices('TVPhilips') -- nazwa ping (ustawiony jako motion sensor)
if item == motion 
if motion.active and motion1.active then -- detekcja wyzwala skrypt
		switch.switchOn().checkFirst()
else
		switch.switchOff().checkFirst()
end
end
if  item == motion1 and not motion1.active then
   switch.switchOff().checkFirst()
end
}

uwaga zmienne nie mogą się powtarzać.

A działa to tak. Skrypt się uaktywnia tylko ja się zmieni stan czujki ruchu. Sprawdza warunek czy czujka jest aktywna oraz czy telewizor jest włączony. Jak tak to uaktywnia przycisk ze skryptem. W przeciwnym wypadku wyłącza ten przycisk.

 
Dodane : 14/04/2022 10:15 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

@steel_rat zaraz przetestuję , mnie poszło tak ale nie potrafiłem tego ping dodać 

return {
on = {
devices = {
'TekstTV', -- nazwa wlacznik w domoticz
'GarażR' -- nazwa czujnika w domoticz
}
},
data =
{
warunek = { initial = false },
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'PIR Garaż',
},
execute = function(dz, item)

local motion = dz.devices('GarażR') -- nazwa czujnika
local switch = dz.devices('TekstTV') -- nazwa włacznika

if item == motion then -- detekcja aktywna
if motion.active and not switch.active then -- detekcja wyzwala skrypt
dz.data.warunek = true
switch.switchOn().checkFirst()
elseif not motion.active and dz.data.warunek == true then
switch.switchOff().checkFirst()
end
elseif item == switch and item.active and not motion.active then
dz.data.warunek = false
end
end
}

 
Dodane : 14/04/2022 10:22 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

@steel_rat generuje błąd domoticz/scripts/dzVents/generated_scripts/Script #3.lua:4: '}' expected (to close '{' at line 2) near ''TVPhilips''

 
Dodane : 14/04/2022 10:26 pm
(@steel_rat)
Wpisów: 603
Ekspert
 

Bo go będziesz miał w urządzeniach. Tyko do dodania do domoticza. Powinien już być na liście.

Ok poprawiłem bo trochę wpisów po znikało.

return {
on = {
		devices = {
			'GarażR', 'TVPhilips',}
},
logging = {
           level = domoticz.LOG_DEBUG,
            marker = 'PIR Garaż',
},
execute = function(dz, item)
	local motion = dz.devices('GarażR') -- nazwa czujnika
	local switch = dz.devices('TekstTV') -- nazwa włacznika
	local motion1 = dz.devices('TVPhilips') -- nazwa ping (ustawiony jako motion sensor)
	if item == motion then
		if motion.active and motion1.active then -- detekcja wyzwala skrypt
			switch.switchOn().checkFirst()
		else
			switch.switchOff().checkFirst()
		end
	end
	if  item == motion1 and not motion1.active then
		switch.switchOff().checkFirst()
	end
end
}
 
Dodane : 14/04/2022 10:27 pm
Mariusz reacted
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

@steel_rat                     #3.lua:15: 'then' expected near 'if'

 
Dodane : 14/04/2022 10:43 pm
(@steel_rat)
Wpisów: 603
Ekspert
 

No bo then zjadłem 🙁 poprawiłem.

 
Dodane : 14/04/2022 10:45 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 

@steel_rat ogarnąłem właśnie testuję

 
Dodane : 14/04/2022 10:50 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 
2022-04-14 23:54:42.101 Error: dzVents: Error: (3.1.8) error loading module 'Script #3' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #3.lua':
2022-04-14 23:54:42.101 ...domoticz/scripts/dzVents/generated_scripts/Script #3.lua:24: unexpected symbol near '}'
 
 
Dodane : 14/04/2022 10:55 pm
(@steel_rat)
Wpisów: 603
Ekspert
 

jeszcze jedno end przed } na końcu wpisz

 
Dodane : 14/04/2022 11:02 pm
Mariusz
(@mariusz-2)
Wpisów: 228
Weteran Donator 2K23
Autor tematu
 
s: dzVents: Info: Handling events for: "GarażR", value: "On"
2022-04-15 00:05:11.536 Status: dzVents: Info: PIR Garaż: ------ Start internal script: Script #3: Device: "GarażR (zigbee2mqtt)", Index: 115
2022-04-15 00:05:11.538 Status: dzVents: Debug: PIR Garaż: Processing device-adapter for TekstTV: Switch device adapter
2022-04-15 00:05:11.540 Status: dzVents: Debug: PIR Garaż: Processing device-adapter for TVPhilips: Switch device adapter
2022-04-15 00:05:11.540 Status: dzVents: Debug: PIR Garaż: Constructed timed-command: On
2022-04-15 00:05:11.541 Status: dzVents: Debug: PIR Garaż: Constructed timed-command: On
 
 
Działa , dziękuję za pomoc i naukę.
 
Dodane : 14/04/2022 11:07 pm
Udostępnij: