Page 1 of 1
Water leak script (Blockly to dzVents)
Posted: Friday 11 January 2019 18:37
by QSKONE
Hi , I try convert every my blockly scripts to dzVents and it is successful. Excluding one - simple water leak script. Problem is water leak from dzVents script cannot switch on any device. Why? What is wrong? Thanks
Code: Select all
return {
on = { devices = { 8 }}, --- xiaomi water leak
execute = function(dz, item )
waterleak = dz.devices( 8 ).state --- xiaomi water leak
gateway = dz.devices( 1 ).state --- xiaomi gateway rgb
alarm = dz.devices( 2 ).selector --- alarm ringtone state
hue = dz.devices( 31 ).selector --- mi gateway hue
brightnes = dz.devices( 32 ).selector --- mi gateway bri
if dz.devices( 8 ).state == "0n" then
dz.devices( 1 ).switchOn().forMin (1)
dz.devices( 2 ).switchSelector(10).forMin(1)
dz.devices( 31 ).switchSelector(100)
dz.devices( 32 ).switchSelector(100)
end
end
}
Re: Water leak script (Blockly to dzVents)
Posted: Friday 11 January 2019 18:43
by waaren
QSKONE wrote: ↑Friday 11 January 2019 18:37
Hi , I try convert every my blockly scripts to dzVents and it is successful. Excluding one - simple water leak script. Problem is water leak from dzVents script cannot switch on any device. Why? What is wrong? Thanks
Without the log it is hard to say but my first guess is this line.
Code: Select all
dz.devices( 2 ).switchSelector(10).forMin(1)
Maybe better to change is in something like
Code: Select all
dz.devices( 2 ).switchSelector(10)
dz.devices( 2 ).switchSelector(dz.devices(2).level).afterMin(1)
Re: Water leak script (Blockly to dzVents)
Posted: Friday 11 January 2019 18:56
by QSKONE
@waaren
Script start ok
Code: Select all
2019-01-11 18:51:22.302 Status: dzVents: Info: Handling events for: "Xiaomi Water Leak Detector", value: "On"
2019-01-11 18:51:22.309 Status: dzVents: Info: ------ Start internal script: Water leak dzVents: Device: "Xiaomi Water Leak Detector (Xiaomi Gateway)", Index: 8
2019-01-11 18:51:22.332 Status: dzVents: Info: ------ Finished Water leak dzVents
When i try simple example
Code: Select all
if dz.devices(water leak sensor).state == 'On' then
dz.devices(any light).switchOn()
Light Will Not Turned On
Re: Water leak script (Blockly to dzVents)
Posted: Friday 11 January 2019 19:03
by waaren
QSKONE wrote: ↑Friday 11 January 2019 18:56
@waaren
Script start ok
Code: Select all
2019-01-11 18:51:22.302 Status: dzVents: Info: Handling events for: "Xiaomi Water Leak Detector", value: "On"
2019-01-11 18:51:22.309 Status: dzVents: Info: ------ Start internal script: Water leak dzVents: Device: "Xiaomi Water Leak Detector (Xiaomi Gateway)", Index: 8
2019-01-11 18:51:22.332 Status: dzVents: Info: ------ Finished Water leak dzVents
When i try simple
Code: Select all
if dz.devices(water leak sensor).state == 'On' then
dz.devices(any light).switchOn()
Light Will Not Turned On
Your last code snippet will definitely not work.
Code: Select all
dz.devices(water leak sensor).state
will always nil or an error. Try
Code: Select all
dz.devices("water leak sensor").state
Re: Water leak script (Blockly to dzVents)
Posted: Friday 11 January 2019 19:26
by QSKONE
Script with device 8 - water leak sensor works
Code: Select all
return {
on = { devices = { 8 }}, --- xiaomi water leak
execute = function(dz)
waterleak = dz.devices( 8 ).state --- xiaomi water leak
light = dz.devices( 76 ).state --- shelly 1.1
if dz.devices( 8 ).state == 'On' then
dz.devices( 76 ).switchOn()
end
end
}
When I change water leak sensor for xiaomi button script works too
Code: Select all
return {
on = { devices = { 90 }}, ---xiaomi button 3 idx 90
execute = function(dz, item )
button = dz.devices( 90 ).state --- xiaomi button
waterleak = dz.devices( 8 ).state --- xiaomi water leak
gateway = dz.devices( 1 ).state --- xiaomi gateway rgb
alarm = dz.devices( 2 ).selector --- alarm ringtone state
hue = dz.devices( 31 ).selector --- mi gateway hue
brightnes = dz.devices( 32 ).selector --- mi gateway bri
if dz.devices( 90 ).state == "Click" then
dz.devices( 1 ).switchOn().forMin (1)
dz.devices( 2 ).switchSelector(10).forMin(1)
dz.devices( 31 ).switchSelector(100)
dz.devices( 32 ).switchSelector(100)
end
end
}
But water leak script with water leak sensor still dont work. Any ideas?
Re: Water leak script (Blockly to dzVents)
Posted: Friday 11 January 2019 19:46
by QSKONE
---
Re: Water leak script (Blockly to dzVents)
Posted: Friday 11 January 2019 21:26
by waaren
QSKONE wrote: ↑Friday 11 January 2019 19:46---
Can you try with this one. It will produce some extra loglines that might help in finding what the problem is. Also changed selector to level as selector is not a valid attribute
Code: Select all
return {
on = { devices = { 8 }}, --- xiaomi water leak
logging = {
level = domoticz.LOG_DEBUG,
marker = "waterLeak"
},
execute = function(dz, item)
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end
local xWaterleak = item --- xiaomi water leak
local xButton = dz.devices( 90 ) --- xiaomi button
local xGateway = dz.devices( 1 ) --- xiaomi gateway rgb
local xAlarm = dz.devices( 2 ) --- alarm ringtone state
local xHue = dz.devices( 31 ) --- mi gateway hue
local xBrightnes = dz.devices( 32 ) --- mi gateway bri
local button = xButton.state
local waterleak = xWaterleak.state
local gateway = xGateway.state
local alarm = xAlarm.level
local hue = xHue.level
local brightnes = xBrightnes.level
logWrite("State of ".. xWaterleak.name .. " is " .. waterleak)
logWrite("State of ".. xGateway.name .. " is " .. gateway)
logWrite("level of ".. xAlarm.name .. " is " .. alarm)
logWrite("level of ".. xHue.name .. " is " .. hue)
logWrite("level of ".. xBrightnes.name .. " is " .. brightnes)
if waterleak == "On" then
xGateway.switchOn().forMin (1)
xAlarm.switchSelector(10).forMin(1)
xHue.switchSelector(100)
xBrightnes.switchSelector(100)
end
end
}
Re: Water leak script (Blockly to dzVents)
Posted: Saturday 12 January 2019 12:04
by QSKONE
@waaren thank you for help ,inspiration and patience. Your last script work but it is huge. I rewrote completely script to tiny version.
Code: Select all
return {
active = true,
on = {
devices = {
'Xiaomi Water Leak Detector'
}
},
execute = function(dz)
if dz.devices( 'Xiaomi Water Leak Detector' ).state == 'On' then
dz.devices('Xiaomi Gateway RGB').switchSelector(100)
dz.devices('Xiaomi Gateway RGB').setRGB(255, 0, 0)
dz.devices('Xiaomi Gateway Alarm Ringtone').switchSelector(10).forMin(1)
end
end
}
Video:
https://youtu.be/hCZC_APVWzo
Everything works fine ,but in log have this error.
Code: Select all
Error: Error opening url: http://127.0.0.1:8080/json.htm?param=setcolbrightnessvalue&type=command&idx=1&hue=0&brightness=100&iswhite=false
I do not understand because I do not use 127.0.0.1 anywhere.
Re: Water leak script (Blockly to dzVents) [Solved]
Posted: Saturday 12 January 2019 12:21
by waaren
QSKONE wrote: ↑Saturday 12 January 2019 12:04
@waaren thank you for help ,inspiration and patience. Your last script work but it is huge. I rewrote completely script to tiny version.
Code: Select all
return {
active = true,
on = {
devices = {
'Xiaomi Water Leak Detector'
}
},
execute = function(dz)
if dz.devices( 'Xiaomi Water Leak Detector' ).state == 'On' then
dz.devices('Xiaomi Gateway RGB').switchSelector(100)
dz.devices('Xiaomi Gateway RGB').setRGB(255, 0, 0)
dz.devices('Xiaomi Gateway Alarm Ringtone').switchSelector(10).forMin(1)
end
end
}
Video:
https://youtu.be/hCZC_APVWzo
Everything works fine ,but in log have this error.
Code: Select all
Error: Error opening url: http://127.0.0.1:8080/json.htm?param=setcolbrightnessvalue&type=command&idx=1&hue=0&brightness=100&iswhite=false
I do not understand because I do not use 127.0.0.1 anywhere.
I specifically wrote the extra lines to help you investigating what's happening during the execution of the script. So hopefully that was useful for you to get to a working version.
the Error about 127.0.0.1 is a classic. Please read the wiki and start with
Using dzVents with Domoticz , where you will read:
Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz.
Re: Water leak script (Blockly to dzVents)
Posted: Monday 14 January 2019 20:46
by waaren
Mayki wrote: ↑Monday 14 January 2019 20:24
Is it possible to control multiple Xiaomi Water Leak Detector with one script?
Xiaomi Water Leak Detector and Xiaomi Water Leak Detector 2 etc.
Yes. See below
Code: Select all
return {
active = true,
on = {
devices = {
'Xiaomi Water Leak Detector',
'Xiaomi Water Leak Detector 2',
'Xiaomi Water Leak Detector 3',
}
},
execute = function(dz, item)
if item.state == 'On' then
dz.devices('Xiaomi Gateway RGB').switchSelector(100)
dz.devices('Xiaomi Gateway RGB').setRGB(255, 0, 0)
dz.devices('Xiaomi Gateway Alarm Ringtone').switchSelector(10).forMin(1)
dz.notify("Water leakage", item.name, dz.PRIORITY_EMERGENCY)
end
end
}