Re: Perte du fonctionnement des BLOCKY
Publié : 16 août 2020, 12:52
J'ai une quarantaine de blockys simples.
Seulement 30 sont activés.
Seulement 30 sont activés.
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
Code : Tout sélectionner
#!/bin/sh
##### POUR LA CAMERA PARKING #############
#Entrer ici le token du bot telegram :
token="xxxxxxxxx"
#Entrer ici le channel de réception de la photo :
SendMsgTo="xxxxxxxx"
#Entrer ici le délai entre les 2 photos :
pausebetween=2
#URL :
DomoUrl="xxx.xxx.x.xx:xxxx"
SnapFile1="/var/tmp/15.jpg"
SnapFile2="/var/tmp/16.jpg"
# get first Picture
wget -O $SnapFile1 $DomoUrl"/camsnapshot.jpg?idx=2"
sleep $pausebetween
# get second Picture
wget -O $SnapFile2 $DomoUrl"/camsnapshot.jpg?idx=2"
# send a group
curl -s \
-X POST "https://api.telegram.org/bot"$token"/sendMediaGroup" \
-F chat_id="$SendMsgTo" \
-F media='[{"type":"photo","media":"attach://photo_1","caption":""},{"type":"photo","media":"attach://photo_2","caption":"PARKING"}]' \
-F photo_1="@$SnapFile1" \
-F photo_2="@$SnapFile2"
# remove Pictures
rm $SnapFile1
rm $SnapFile2Code : Tout sélectionner
local scriptVar = 'lastSeen'
return {
--on = { timer = {'every 30 minutes'}, httpResponses = { scriptVar }},
on = { timer = {'every minute'}, httpResponses = { scriptVar }}, -- Only use this one to test. When working disable it and activate "every 30 minutes"
--on = { timer = {'at 08:00', 'at 10:00'}, httpResponses = { scriptVar }},
logging = { level = domoticz.LOG_ERROR, marker = scriptVar },
data = { notified = { initial = {} } },
execute = function(dz, item)
--Telegram settings
local telegram = true -- Set true for sending telegram, set false for NOT sending telegram.
--Email settings (domoticz email settings have to be filled in)
local email = true -- Set true for sending email, set false for NOT sending email.
local mailaddress = 'xxx.xxx@gmail.com' -- Fill in your e-mail address, which the notification needs to be send to.
-- Global settings
local notifyTime = 'at 10:00','at 20:00' -- You can add multiple notification times, i.e. 'at 12:00, at 20:00'
local notifyHead = 'dzCheckSensors' -- This is the start of everynotification, so you know it is this script.
-- Devices to check NO holiday.
-- Devices name or IDX number column = Time column in seconds
local devices_No = {
['Batterie Détecteur 1'] = 7200, -- 2 Hour
['Batterie Détecteur 2'] = 7200, -- 2 Hour
['Batterie Détecteur 3'] = 7200, -- 2 Hour
['Batterie Détecteur 4'] = 7200, -- 2 Hour
['Batterie INONDATION AQUARIUM'] = 7200, -- 2 Hour
['Batterie Capteur Parking'] = 7200, -- 2 Hour
['Batterie Capteur Escalier'] = 7200, -- 2 Hour
['Batterie Capteur Baie Jardin'] = 7200, -- 2 Hour
['Batterie Cabanon'] = 7200, -- 2 Hour
['Batterie Bouton LED LIT Couloir'] = 7200, -- 2 Hour
['Batterie Bouton LED LIT'] = 7200, -- 2 Hour
['Batterie Détecteur Incendie'] = 7200, -- 2 Hour
['Batterie Porte dentrée'] = 7200, -- 2 Hour
['Batterie Sonde BUREAU'] = 7200, -- 2 Hour
['Batterie Sonde GARAGE'] = 7200, -- 2 Hour
['Batterie Volets RDC'] = 7200, -- 2 Hour
}
-- Devices to check when it is holiday.
-- Devices name or IDX number column = Time column in seconds
local devices_Yes = {
['Batterie Détecteur 1'] = 1209600, -- 14 Days IDX335=Dashboard-webpage-check
['Batterie Détecteur 2'] = 1209600, -- 14 Days
['Batterie Détecteur 3'] = 1209600, -- 14 Days
['Batterie Détecteur 4'] = 1209600, -- 14 Days
['Batterie INONDATION AQUARIUM'] = 1209600, -- 14 Days
['Batterie Capteur Parking'] = 1209600, -- 14 Days
['Batterie Capteur Escalier'] = 1209600, -- 14 Days
['Batterie Capteur Baie Jardin'] = 1209600, -- 14 Days
['Batterie Cabanon'] = 1209600, -- 14 Days
['Batterie Bouton LED LIT Couloir'] = 1209600, -- 14 Days
['Batterie Bouton LED LIT'] = 1209600, -- 14 Days
['Batterie Détecteur Incendie'] = 1209600, -- 14 Days
['Batterie Porte dentrée'] = 1209600, -- 14 Days
['Batterie Sonde BUREAU'] = 1209600, -- 14 Days
['Batterie Sonde GARAGE'] = 1209600, -- 14 Days
['Batterie Volets RDC'] = 1209600, -- 14 Days
}
-- Don't change things undernead this line
local notified = dz.data.notified -- short reference
function Timers(sec)
local ti
sec=tonumber(sec)
if sec == nil then ti='NIL'
elseif sec >= 86400 then ti=string.sub(tostring(sec/24/3600),1,4)..' days'
elseif sec >= 3600 then ti=string.sub(tostring(sec/3600),1,4)..' hours'
elseif sec >= 60 then ti=string.sub(tostring(sec/60),1,4)..' minutes'
else ti=sec..' seconds'
end
return ti
end
if not (item.isHTTPResponse) then
dz.openURL({
url = dz.settings['Domoticz url'] .. '/json.htm?type=devices&used=true',
callback = scriptVar })
else
if dz.devices('opVakantie').state== 'On' then
dz.log(notifyHead .." ".. 'Vakantie-On',dz.LOG_FORCE)
DevicesToCheck = devices_Yes
else
dz.log(notifyHead .." ".. 'Vakantie-Off',dz.LOG_FORCE)
DevicesToCheck = devices_No
end
local Time = require('Time')
for _, node in pairs(item.json.result) do
local toCheck = ( DevicesToCheck[node.idx] or DevicesToCheck[node.Name])
if toCheck then
local lastUpdate = Time(node.LastUpdate).secondsAgo
local deviceName = (node.Name or node.idx)
local threshold = toCheck
if lastUpdate < threshold then
--device is alive
if notified[deviceName] == nil then
dz.log(notifyHead .." "..deviceName.." : "..Timers(lastUpdate).. ' was last response, threshold='..Timers(threshold),dz.LOG_FORCE)
else
dz.log(notifyHead .." ".. ' Signal back from sensor '..deviceName,dz.LOG_FORCE)
notified[deviceName] = nil --remove from notified list
if telegram then
dz.notify(notifyHead, notifyHead .." ".. 'Signal back from sensor '..deviceName..'.',dz.PRIORITY_NORMAL,nil,nil,dz.NSS_TELEGRAM)
end
if email then
dz.email('Domoticz device check', ''..notifyHead.. ' Signal back from sensor '..deviceName..'', ''..mailaddress..'')
end
end
else
--lost signal:
if notified[deviceName] == nil then
dz.log (notifyHead .." ".. 'Signal lost: '..deviceName .." sent "..Timers(lastUpdate).. ' the last signal, threshold='..Timers(threshold)..'. Battery empty?',dz.LOG_FORCE)
notified[deviceName] = 1
if telegram then
dz.notify(notifyHead, notifyHead ..' Signal lost: '..deviceName ..' sent '..Timers(lastUpdate).. ' the last signal, threshold='..Timers(threshold)..'. Battery empty?',dz.PRIORITY_NORMAL,nil,nil,dz.NSS_TELEGRAM)
end
if email then
dz.email('Domoticz device check', ''..notifyHead..' Signal lost: '..deviceName ..' sent '..Timers(lastUpdate).. ' the last signal, threshold='..Timers(threshold)..'. Battery empty?', ''..mailaddress..'')
end
elseif
dz.time.matchesRule(notifyTime) and
dz.devices('opVakantie').state == 'Off'
then
dz.log(notifyHead .." ".. 'Reminder, '..deviceName .." sent "..Timers(lastUpdate).. ' the last signal. Battery empty?',dz.LOG_FORCE)
if telegram then
dz.notify(notifyHead, notifyHead .." ".. 'Reminder, '..deviceName .." sent "..Timers(lastUpdate).. ' the last signal. Battery empty?',dz.PRIORITY_NORMAL,nil,nil,dz.NSS_TELEGRAM)
end
if email then
dz.email('Domoticz device check', ''..notifyHead..' Signal lost: '..deviceName ..' sent '..Timers(lastUpdate).. ' the last signal, threshold='..Timers(threshold)..'. Battery empty?', ''..mailaddress..'')
end
end
end
end
end
end
end
}