Easy to use, 100% Lua-based event scripting framework.
Moderator: leecollings
Hydci
Posts: 35 Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:
Post
by Hydci » Monday 11 November 2019 17:11
Hello I have this script that works great I just have a problem I would like him to update the device only when the state changes I tried several things but I can not do it
Code: Select all
return
{
on = { timer = { 'every minute' },
httpResponses = { 'vigilance' }},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Vigilance'
},
execute = function(dz, item, level)
local SaisonURL = 'http://domogeek.entropialux.com/vigilance/59/color'
if not(item.isHTTPResponse) then
dz.openURL({ url = SaisonURL, callback = 'vigilance' })
elseif item.ok then
if item.data == 'vert' and dz.devices('Vigilance météo') ~= '1' then
dz.devices('Vigilance météo').updateAlertSensor('1', 'Alerte vert')
elseif item.data == 'jaune' and dz.devices('Vigilance météo') ~= '2' then
dz.devices('Vigilance météo').updateAlertSensor('2','Alerte jaune')
elseif item.data == 'orange' and dz.devices('Vigilance météo') ~= '3' then
dz.devices('Vigilance météo').updateAlertSensor('3', 'Alerte orange')
elseif item.data == 'rouge' and dz.devices('Vigilance météo') ~= '4' then
dz.devices('Vigilance météo').updateAlertSensor('4', 'Alerte rouge')
end
end
end
}
waaren
Posts: 6028 Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:
Post
by waaren » Monday 11 November 2019 17:37
Hydci wrote: ↑ Monday 11 November 2019 17:11
Hello I have this script that works great I just have a problem I would like him to update the device only when the state changes I tried several things but I can not do it
Can you try this ?
Code: Select all
return
{
on = { timer = { 'every minute' },
httpResponses = { 'vigilance' }},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Vigilance'
},
execute = function(dz, item)
if not(item.isHTTPResponse) then
local SaisonURL = 'http://domogeek.entropialux.com/vigilance/59/color'
dz.openURL({ url = SaisonURL, callback = 'vigilance' })
return
end
local vigilance = dz.devices(131) -- Change to the id of your Alert sensor
local currentColor = vigilance.color
local colorMapping =
{
gris = dz.ALERTLEVEL_GREY,
vert = dz.ALERTLEVEL_GREEN,
jaune = dz.ALERTLEVEL_YELLOW,
orange = dz.ALERTLEVEL_ORANGE,
rouge = dz.ALERTLEVEL_RED,
}
if item.ok then
if currentColor ~= colorMapping[item.data] then
vigilance.updateAlertSensor(colorMapping[item.data], 'Alerte ' .. item.data)
else
dz.log('No update needed. Sensor is already '.. item.data , dz.LOG_DEBUG)
end
else
dz.log('problem retrieving data',dz.LOG_ERROR)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki
waaren
Posts: 6028 Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:
Post
by waaren » Monday 11 November 2019 17:53
or if you want to use other data from this site in future..
Code: Select all
return
{
on = { timer = { 'every minute' },
httpResponses = { 'vigilance' }},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Vigilance'
},
execute = function(dz, item)
if not(item.isHTTPResponse) then
local SaisonURL = 'http://domogeek.entropialux.com/vigilance/59/all'
dz.openURL({ url = SaisonURL, callback = 'vigilance' })
return
end
local vigilance = dz.devices(131) -- change to id of your alert Sensor
local currentColor = vigilance.color
local colorMapping =
{
gris = dz.ALERTLEVEL_GREY,
vert = dz.ALERTLEVEL_GREEN,
jaune = dz.ALERTLEVEL_YELLOW,
orange = dz.ALERTLEVEL_ORANGE,
rouge = dz.ALERTLEVEL_RED,
}
if item.ok then
local newColor = item.json.vigilancecolor
if colorMapping[newColor] ~= currentColor then
vigilance.updateAlertSensor(colorMapping[newColor], 'Alerte ' .. newColor)
else
dz.log('No update needed. Sensor is already '.. newColor , dz.LOG_DEBUG)
end
else
dz.log('problem retrieving data ' .. item.data,dz.LOG_ERROR)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki
Hydci
Posts: 35 Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:
Post
by Hydci » Monday 11 November 2019 17:58
It works perfectly the device is no longer updated every minute but I have another script that sends a notification to the color change is that it? because it does not work
if value.data == "1" is good ?
Code: Select all
return {
on = { devices = { "vigilance météo" }},
execute = function(dz, item, devices, value )
if value.data == "1" then
os.execute("xxxxx'")
elseif value.data == "2" then
os.execute("xxxx'")
elseif value.data == "3" then
os.execute("xxxx'")
elseif value.data == "4" then
os.execute("xxxx'")
end
end
}
Edit:
My script work
Code: Select all
return {
on = { devices = { "Vigilance météo" }},
execute = function(dz, item, devices, value )
if item.state == "Alerte vert" then
os.execute("curl -u Hydci:Daniel15042015 -s -o -v 'http://192.168.1.4:7080/send.html?smsto=xxxx&smsbody=Fin+de+lalerte+meteo+france&smstype=sms'")
elseif item.state == "Alerte jaune" then
os.execute("curl -u Hydci:Daniel15042015 -s -o -v 'http://192.168.1.4:7080/send.html?smsto=xxxxx&smsbody=Bo%C3%AEte+au+lettre+courrier+dedans&smstype=sms'")
elseif item.state == "Alerte orange" then
os.execute("curl -u Hydci:Daniel15042015 -s -o -v 'http://192.168.1.4:7080/send.html?smsto=xxxxx&smsbody=Bo%C3%AEte+au+lettre+courrier+dedans&smstype=sms'")
elseif item.state == "Alerte rouge" then
os.execute("curl -u Hydci:Daniel15042015 -s -o -v 'http://192.168.1.4:7080/send.html?smsto=xxxx&smsbody=Bo%C3%AEte+au+lettre+courrier+dedans&smstype=sms'")
end
end
}
Last edited by
Hydci on Monday 11 November 2019 18:23, edited 2 times in total.
waaren
Posts: 6028 Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:
Post
by waaren » Monday 11 November 2019 18:12
Hydci wrote: ↑ Monday 11 November 2019 17:58
It works perfectly the device is no longer updated every minute but I have another script that sends a notification to the color change is that it? because it does not work
if value.data == "1" is good ?
No. It should be something like
Code: Select all
return {
on = { devices = { "vigilance météo" }},
execute = function(dz, item )
if item.color == dz.ALERTLEVEL_GREEN then
os.execute("xxxxx")
elseif item.color == dz.ALERTLEVEL_YELLOW then
os.execute("xxxx")
elseif item.color == dz.ALERTLEVEL_ORANGE then
os.execute("xxxx")
elseif item.color == dz.ALERTLEVEL_RED then
os.execute("xxxx")
end
end
}
Is there a specific reason why you do not combine this with the previous script ?
something like
Code: Select all
return
{
on = { timer = { 'every minute' },
httpResponses = { 'vigilance' }},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Vigilance'
},
execute = function(dz, item)
if not(item.isHTTPResponse) then
local SaisonURL = 'http://domogeek.entropialux.com/vigilance/59/all'
dz.openURL({ url = SaisonURL, callback = 'vigilance' })
return
end
local vigilance = dz.devices(131)
local currentColor = vigilance.color
local colorMapping =
{
gris = dz.ALERTLEVEL_GREY,
vert = dz.ALERTLEVEL_GREEN,
jaune = dz.ALERTLEVEL_YELLOW,
orange = dz.ALERTLEVEL_ORANGE,
rouge = dz.ALERTLEVEL_RED,
}
if item.ok then
local newColor = item.json.vigilancecolor
if colorMapping[newColor] ~= currentColor then
vigilance.updateAlertSensor(colorMapping[newColor], 'Alerte ' .. newColor)
if newColor == dz.ALERTLEVEL_GREEN then
os.execute("xxxxx")
elseif newColor == dz.ALERTLEVEL_YELLOW then
os.execute("xxxx")
elseif newColor == dz.ALERTLEVEL_ORANGE then
os.execute("xxx")
elseif newColor == dz.ALERTLEVEL_RED then
os.execute("xx")
end
else
dz.log('No update needed. Sensor is already '.. newColor , dz.LOG_DEBUG)
end
else
dz.log('problem retrieving data ' .. item.data,dz.LOG_ERROR)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki
Hydci
Posts: 35 Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:
Post
by Hydci » Monday 11 November 2019 18:15
I did not think it was possible thanks for the solution
Users browsing this forum: No registered users and 0 guests