first commit

This commit is contained in:
Souti
2025-03-06 11:09:58 +01:00
commit 11f7d440ff
330 changed files with 38306 additions and 0 deletions

8
dzVents/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
# Created by .ignore support plugin (hsz.mobi)
/domoticzData.lua
scripts/*.lua
data/*.lua
generated_scripts/*.lua
!/runtime/tests/data/README.md
/runtime/tests/data/__data_global_data.lua
/runtime/tests/data/__data_script1.lua

1
dzVents/data/README.md Normal file
View File

@@ -0,0 +1 @@
This folder will contains the data files for scripts. If a script uses the `data` section then dzVents stores the persistent data in this folder. If a script doesn't seem to work properly with regards to the persistent data, then you can remove the corresponding data file here.

4
dzVents/dumps/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@@ -0,0 +1,18 @@
--[[
Log level = 1: Errors
Log level = 1.5: Errors + info about the execution of individual scripts and a dump of the commands sent back to Domoticz
Log level = 2: Errors + info
Log level = 3: Debug info + Errors + Info (can be a lot!!!)
Log level = 0: As silent as possible
About the fetch interval: there's no need to have a short interval in normal
situations. dzVents will only use it for battery level and some other information
that doesn't change very often.
]]--
return {
['Domoticz ip'] = '10.0.0.8',
['Domoticz port'] = '8080',
['Fetch interval'] = 'every 30 minutes', -- see readme for timer settings
['Enable http fetch'] = true, -- only works on linux systems
['Log level'] = 2
}

View File

@@ -0,0 +1,22 @@
--[[
Assume you have two temperature sensors and a third dummy sensor that should be the
difference of these two sensors (e.g. you want to see the difference between water temperature
going into a radiator and the temperature of the water going out of it
]]--
return {
active = true,
on = {
['timer'] = {'every 5 minutes'}
},
execute = function(domoticz)
local inTemp = domoticz.devices('Temp in').temperature
local outTemp = domoticz.devices('Temp out').temperature
local delta = outTemp - inTemp -- how much did the temperature drop?
-- update the dummy sensor
domoticz.devices('Delta temp').updateTemperature(delta)
end
}

View File

@@ -0,0 +1,37 @@
local BATTERY_THRESHOLD = 10
return {
active = true,
on = {
['timer'] = {
'every hour'
}
},
execute = function(domoticz)
local message = ''
-- first filter on low battery level
local lowOnBat = domoticz.devices().filter(function(device)
local level = device.batteryLevel -- level is 0-100
return (level ~= nil and -- not all devices have this attribute
level <= BATTERY_THRESHOLD)
end)
-- then loop over the results
lowOnBat.forEach(function(lowDevice)
message = message .. 'Device ' ..
lowDevice.name .. ' is low on batteries (' .. tostring(lowDevice.batteryLevel) .. '), '
end)
if (message ~= '') then
domoticz.notify('Low battery warning', message, domoticz.PRIORITY_NORMAL)
domoticz.log('Low battery warning: ' .. message, domoticz.LOG_ERROR)
end
end
}

View File

@@ -0,0 +1,36 @@
--Check dead device using their description
--This allow to configure device to be checked directly in domoticz GUI by accessing to device details and add "CDA:<delayInMinute>"
--You have to active http fetching !
return {
active = true,
on = {
['timer'] = {
'every 60 minutes'
}
},
execute = function(domoticz)
local message=""
domoticz.devices().forEach(function(device)
if (device.description ~= nil) then
_, _, threshold = string.find(device.description,"CDA:(%d+)")
if (threshold ~= nil) then
local name = device.name
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
if ( minutes > tonumber(threshold)) then
message = message .. 'Device ' ..
name .. ' seems to be dead. No heartbeat for at least ' ..
minutes .. ' minutes.\r'
end
end
end
end)
if (message ~= "") then
domoticz.notify('Dead devices', message, domoticz.PRIORITY_HIGH)
domoticz.log('Dead devices found: ' .. message, domoticz.LOG_ERROR)
end
end
}

View File

@@ -0,0 +1,37 @@
local devicesToCheck = {
{ ['name'] = 'Sensor1', ['threshold'] = 30 },
{ ['name'] = 'Sensor2', ['threshold'] = 30 },
{ ['name'] = 'Bathroom temperature', ['threshold'] = 20 }
}
return {
active = true,
on = {
['timer'] = {
'every 5 minutes'
}
},
execute = function(domoticz)
local message = ""
for i, deviceToCheck in pairs(devicesToCheck) do
local name = deviceToCheck['name']
local threshold = deviceToCheck['threshold']
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
if ( minutes > threshold) then
message = message .. 'Device ' ..
name .. ' seems to be dead. No heartbeat for at least ' ..
minutes .. ' minutes.\r'
end
end
if (message ~= "") then
domoticz.email('Dead devices', message, 'me@address.nl')
domoticz.log('Dead devices found: ' .. message, domoticz.LOG_ERROR)
end
end
}

View File

@@ -0,0 +1,22 @@
-- External light
-- turn lights on at sunset and back off at sunrise
return {
active = true,
on = {
timer = {
'at sunset',
'at sunrise'
}
},
execute = function(domoticz, timer)
-- external light switch name
local external_light = domoticz.devices('External light')
if (timer.trigger == 'at sunset') then
external_light.switchOn()
else
external_light.switchOff()
end
end
}

View File

@@ -0,0 +1,23 @@
-- example script to fake the presence of people being at home
return {
active = true,
on = {
timer = {
'at sunset',
'at 23:30'
}
},
execute = function(domoticz, timer)
if (timer.trigger == 'at sunset') then
domoticz.devices('mySwitch').switchOn()
domoticz.devices('anotherSwitch').dimTo(40)
-- add whatever you want
else
-- switch off at a random moment after 23:30
domoticz.devices('mySwitch').switchOff().withinMin(60)
domoticz.devices('anotherSwitch').switchOff().withinMin(60)
end
end
}

View File

@@ -0,0 +1,27 @@
--[[
From the domoticz examples online:
http://www.domoticz.com/wiki/Event_script_examples
Send a warning when the garage door has been open for more than 10 minutes
]]
return {
active = true,
on = {
['timer'] = {
'every minute',
}
},
execute = function(domoticz)
local door = domoticz.devices('Garage door')
if (door.state == 'Open' and door.lastUpdate.minutesAgo > 10) then
domoticz.notify('Garage door alert',
'The garage door has been open for more than 10 minutes!',
domoticz.PRIORITY_HIGH)
end
end
}

View File

@@ -0,0 +1,23 @@
-- See README.md for instructions
return {
active = false, -- set to true to activate this script
on = {
'My switch', -- name of the device
'My sensor_Temperature', -- better not use but check device.attributeIsChanged('temperature')
'My sensor',
258, -- index of the device
['timer'] = 'every minute', -- see readme for more options and schedules
'PIR_*', -- triggers for all devices which name begins with PIR_
},
execute = function(domoticz, mySwitch) -- see readme for what you get
-- see readme for the entire domoticz object tree
-- mySwitch is a Device object with all the properties of the device that was updated
-- unless this is a timer script, then there is not second parameter to this execute function
if (mySwitch.state == 'On') then
domoticz.notify('Hey!', 'I am on!', domoticz.PRIORITY_NORMAL)
end
end
}

View File

@@ -0,0 +1,19 @@
return {
active = true,
on = {
devices = {
'My sensor'
}
},
execute = function(domoticz, mySensor)
if (mySensor.temperature > 50) then
domoticz.notify('Hey!', 'The house might be on fire!!',
domoticz.PRIORITY_EMERGENCY,
domoticz.SOUND_SIREN)
domoticz.log('Fire alert', domoticz.LOG_ERROR)
end
end
}

View File

@@ -0,0 +1,25 @@
return {
active = true,
on = {
devices = {
'PIR_*' -- all my motion detectors' name start with PIR_
}
},
execute = function(domoticz, detector)
if (detector.state == 'Motion' and domoticz.security ~= domoticz.SECURITY_DISARMED) then
-- o dear
domoticz.setScene('intruder alert', 'On')
-- send notification
domoticz.notify('Security breach', '',
domoticz.PRIORITY_EMERGENCY,
domoticz.SOUND_SIREN)
end
end
}

View File

@@ -0,0 +1,72 @@
-- Water leak detection
--
-- assumptions:
-- need 2 devices :
-- a Water Flow devices name "Water_Flow"
-- a Dummy Device type percentage "Leakage_Percent"
--
-- 1 / leakage "open valve"
-- Every minute if a non-zero water flow is present, it increments a counter (Leakage_Percent)
-- If the water flow is zero is that it leaks more continuously.
-- A notification can be put on "Leakage_Percent" if >80% (80% = 80 minutes of continuous flow)
--
-- 2 / "micro continuous flow" (drip)
-- in 24 hours one must have at least 2 hours without flow (detection 0.5 liters / hour is 4.5m3 / year)
-- if not, "Leakage_Percent" is forced at 100%.
local FLOW_DEVICE = 'Water_Flow' -- Flow device
local LEAK_DEVICE = 'Leakage_Percent' -- percent dummy device
return {
active = true,
on = {
['timer'] = {
'every minute'
}
},
data = {
time_0_flow = { initial = 0 },
total_time = { initial = 0 },
},
execute = function(domoticz)
-- Flow in liter/minute
local flow = tonumber(domoticz.devices(FLOW_DEVICE).rawData[1])
-- Dummy device in %
local leakage = domoticz.devices(LEAK_DEVICE)
local time_with_flow = tonumber(leakage.rawData[1])
local new_time_with_flow = time_with_flow
-- 1 / leakage "open valve"
if (flow > 0) then
domoticz.data.time_0_flow = 0 -- there is a flow
new_time_with_flow = new_time_with_flow + 1 -- time with flow
if (new_time_with_flow > 100) then
new_time_with_flow = 100
end
else
new_time_with_flow = 0
domoticz.data.time_0_flow = domoticz.data.time_0_flow + 1 -- time without flow
end
-- 2 / flight type "micro continuous flow" (drip)
domoticz.data.total_time = domoticz.data.total_time + 1 -- time without since last 2 hours with no flow
if (domoticz.data.time_0_flow > 120) then
-- 2 hours with no flow
domoticz.data.total_time = 0
elseif (domoticz.data.total_time > (60*24)) then
-- 24 heures since last 2 hours with no flow
new_time_with_flow = 100
end
-- log
domoticz.log(new_time_with_flow .. ' minutes with flow ')
domoticz.log(domoticz.data.time_0_flow .. ' minutes without flow ')
domoticz.log(domoticz.data.total_time .. ' minutes without 2hrs without flow ')
-- update dummy device %
if (time_with_flow ~= new_time_with_flow) then
leakage.update(0,new_time_with_flow)
end
end
}

View File

@@ -0,0 +1,58 @@
-- this script can be used in conjunction with the System-alive checker plug-in.
-- the plugin pings a list of devices and creates switches for these devices
-- the reason for this script is to not treat devices as dead immediately after they
-- do not respond. More often than not, the second ping atempt does work. So only
-- if the device has been not responding for a while AFTER it is been presumed dead
-- then this script will notify you
-- put the names of these switches in the devicesToCheck list
-- you may have to tweak the THRESHOLD depending on the check interval
local THRESHOLD = 5 -- minutes
local devicesToCheck = {'ESP8266 CV', 'ESP8266 ManCave', 'ESP8266 Watermeter'}
return {
active = true,
on = {
devices = {
devicesToCheck
},
timer = {
'every 5 minutes'
}
},
data = {
notified = { initial = {} }
},
execute = function(domoticz, item, triggerInfo)
if (item.isTimer) then
-- check all devices that are off and have not been updated in the past 5 minutes and have not been notified for
for index, deviceName in pairs(devicesToCheck) do
local device = domoticz.devices(deviceName)
if (device.state == 'Off' and
device.lastUpdate.minutesAgo >= THRESHOLD and
domoticz.data.notified[deviceName] == false) then
domoticz.notify(deviceName .. ' is not responding anymore.',' ',domoticz.PRIORITY_HIGH)
-- make sure we only notify once for this device in this case
domoticz.data.notified[deviceName] = true
end
end
else
-- it is the device that was triggered
domoticz.data.notified[item.name] = false
end
end
}

View File

@@ -0,0 +1,23 @@
return {
-- create a function for the active key, when the switch in Domoticz
-- called 'script_blabla' is active, then the script is executed.
-- Note: keep this function really light weight because it is ALWAYS
-- executed in every cycle, even when 'My switch' hasn't changed!!
active = function(domoticz)
return (domoticz.devices('script_blabla').state == 'On')
end,
on = {
devices = {
'My switch'
}
},
execute = function(domoticz, mySwitch)
-- do some weird complicated stuff
-- that takes quite some processing time ;-)
end
}

View File

@@ -0,0 +1,100 @@
--[[
This script can be used to get notification message when plant sensor exceed specified tresholds.
It is specifically build to be used with the Xiaomi Mi Flora (https://www.domoticz.com/wiki/Mi_Flora_Bluetooth_LE), but can also be used with similar sensors
For the script to work correctly it is recommended your device names have the following convention:
Mi Flora - #0 Moisture
Mi Flora - #0 Conductivity
Mi Flora - #1 Moisture
etc. etc.
This is the default device naming when Mi Flora plugin creates devices.
If you have another naming you need to adjust settings below.
]]--
local configuration = {
-- Define the different sensorTypes you want to get notified of
sensorTypes = {
moisture = {
name = 'Moisture', -- Specify substring of name to match ie. "Mi Flora - #1 Moisture"
property = 'percentage' -- property of dzVents device object to use
},
fertility = {
name = 'Conductivity',
property = 'percentage'
}
},
-- Define the plant names and the tresholds (min, max) per sensor below
sensor0 = {
plant = "Calamondin",
tresholds = {
moisture = {30, 60},
fertility = {350, 2000}
}
},
sensor1 = {
plant = "Red pepper",
tresholds = {
moisture = {15, 60},
fertility = {350, 2000}
}
},
sensor2 = {
plant = "Strawberries",
tresholds = {
moisture = {15, 60},
fertility = {350, 2000}
}
},
}
return {
active = true,
on = {
devices = {
'Mi Flora*'
}
},
logging = {
level = domoticz.LOG_DEBUG
},
execute = function(domoticz, device)
local sensorNumber = string.match(device.name, "#(%d+)")
local configKey = 'sensor' .. sensorNumber
if (configuration[configKey] == nil) then
domoticz.log('No configuration defined for sensor #' .. sensorNumber, domoticz.LOG_INFO)
return
end
local sensorConfig = configuration[configKey]
local tresholds = sensorConfig.tresholds
local plantName = sensorConfig.plant
local function checkSensorTresholds(sensorType, notification)
local sensorTypeConfig = configuration.sensorTypes[sensorType]
if (tresholds[sensorType] == nil or not string.match(device.name, sensorTypeConfig.name)) then
domoticz.log(string.format('No tresholds configured for sensor #%d or name does not match' , sensorNumber), domoticz.LOG_DEBUG)
return
end
local value = device[sensorTypeConfig.property]
if (value < tresholds[sensorType][1] or value > tresholds[sensorType][2]) then
notification = string.format(notification, plantName)
notification = notification .. ' | ' .. string.format('%s = %d', sensorType, value)
domoticz.notify('Plants', notification)
domoticz.log(string.format('#%d %s exceeded', sensorNumber, sensorType), domoticz.LOG_DEBUG)
else
domoticz.log(string.format('#%d %s ok', sensorNumber, sensorType), domoticz.LOG_DEBUG)
end
end
checkSensorTresholds('moisture', '%s needs watering')
checkSensorTresholds('fertility', '%s needs fertilization')
end
}

View File

@@ -0,0 +1,24 @@
local RANDOM_DELAY_MINS = 30
return {
active = true,
on = {
['timer'] = {
'at sunset',
'at 01:00'
}
},
execute = function(domoticz)
if (domoticz.security ~= domoticz.SECURITY_DISARMED) then
local light = domoticz.devices('Window light')
if (not light.bState) then -- i.e. state == 'On'
light.switchOn().withinMin(RANDOM_DELAY_MINS)
else
light.switchOff().withinMin(RANDOM_DELAY_MINS)
end
end
end
}

View File

@@ -0,0 +1,14 @@
return {
active = true,
on = {
devices = {
'My switch'
}
},
execute = function(domoticz, mySwitch)
if (mySwitch.state == 'On') then
domoticz.notify('Hey!', 'I am on!', domoticz.PRIORITY_NORMAL)
end
end
}

View File

@@ -0,0 +1,20 @@
return {
active = true,
on = {
['timer'] = {
'at 8:30 on mon,tue,wed,thu,fri',
'at 17:30 on mon,tue,wed,thu,fri',
-- weeekends are different
'at sunset on sat, sun',
'at sunrise on sat, sun'
}
},
execute = function(domoticz)
local pump = domoticz.devices('Pond')
pump.toggleSwitch()
end
}

View File

@@ -0,0 +1,96 @@
-- assumptions:
-- the setpoint is set by a selector dummy device where the values are numeric temperatures
-- but you can easily change it to a setpoint device
local BOILER_DEVICE = 'Boiler' -- switch device
local SETPOINT_DEVICE = 'Setpoint' -- selector dummy device
local TEMPERATURE_SENSOR = 'Temperature'
local HYSTERESIS = 0.5 -- temp has to drop this value below setpoint before boiler is on again
local SMOOTH_FACTOR = 3
local LOGGING = true
return {
on = {
['timer'] = {
'every minute',
},
devices = {
TEMPERATURE_SENSOR,
SETPOINT_DEVICE
}
},
data = {
temperatureReadings = { history = true, maxItems = SMOOTH_FACTOR }
},
active = true,
execute = function(domoticz, item)
local avgTemp
local temperatureReadings = domoticz.data.temperatureReadings
local sensor = domoticz.devices(TEMPERATURE_SENSOR)
local current = sensor.temperature
local boiler = domoticz.devices(BOILER_DEVICE)
local setpoint = domoticz.devices(SETPOINT_DEVICE)
-- first check if the sensor got a new reading or the setpoint was changed:
if (item.isDevice) then
if (sensor.changed) then
-- sensor just reported a new reading
-- add it to the readings table
if (current ~= 0 and current ~= nil) then
temperatureReadings.add(current)
else
-- no need to be here, weird state detected
domoticz.log('Strange sensor reading.. skiping', domoticz.LOG_ERROR)
return
end
elseif (domoticz.devices(SETPOINT_DEVICE).changed) then
-- a new setpoint was set
if LOGGING then domoticz.log('Setpoint was set to ' .. item.state) end
else
-- no business here, bail out...
return
end
end
-- now determine what to do
if (setpoint.state == nil or setpoint.state == 'Off') then
boiler.switchOff()
return -- we're done here
end
local setpointValue = tonumber(setpoint.state)
-- determine at which temperature the boiler should be
-- switched on
local switchOnTemp = setpointValue - HYSTERESIS
-- don't use the current reading but average it out over
-- the past <SMOOTH_FACTOR> readings (data smoothing) to get rid of noise, wrong readings etc
local avgTemp = temperatureReadings.avg(1, SMOOTH_FACTOR, current) -- fallback to current when history is empty
if LOGGING then
domoticz.log('Average: ' .. avgTemp, domoticz.LOG_INFO)
domoticz.log('Setpoint: ' .. setpointValue, domoticz.LOG_INFO)
domoticz.log('Current boiler state: ' .. boiler.state, domoticz.LOG_INFO)
domoticz.log('Switch-on temperature: ' .. switchOnTemp, domoticz.LOG_INFO)
end
if (avgTemp >= setpointValue and boiler.state == 'On') then
if LOGGING then domoticz.log('Target temperature reached, boiler off') end
boiler.switchOff()
end
if (avgTemp < setpointValue and boiler.state == 'Off') then
if (avgTemp < switchOnTemp) then
if LOGGING then domoticz.log('Heating is required, boiler switched on') end
boiler.switchOn()
else
if LOGGING then domoticz.log('Average temperature below setpoint but within hysteresis range, waiting for temperature to drop to ' .. switchOnTemp) end
end
end
end
}

View File

@@ -0,0 +1,132 @@
-- Define all the sensors which needs to be considered for the sunscreen to close
local sensors = {
temperature = {
active = true,
device = 'Temperature',
closeRule = function(device)
return device.temperature <= 15
end
},
wind = {
active = true,
device = 'Wind',
closeRule = function(device)
return device.speed >= 50 or device.gust >= 150
end
},
rain = {
active = true,
device = 'Rain',
closeRule = function(device)
return device.rainRate > 0
end
},
rainExpected = {
active = false,
device = 'Rain expected', -- This needs to be a virtual sensor of type 'percentage'
closeRule = function(device)
return device.percentage > 15
end
},
uv = {
active = true,
device = 'UV',
closeRule = function(device)
return device.uv <= 3
end
},
lux = {
active = false,
device = 'Lux',
closeRule = function(device)
return device.lux <= 500
end
}
}
-- Define the name of your sunscreen device
local sunscreenDevice = 'Sunscreen'
-- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
local dryRun = false
-- Define the name of a virtual switch which you can use to disable the sunscreen automation script
-- Set to false to disable this feature
local manualOverrideSwitch = false
-- Minutes to wait after a sunscreen close before opening it again.
local timeBetweenOpens = 10
return {
active = true,
on = {
timer = {'every minute'}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'Sunscreen'
},
execute = function(domoticz)
local function switchOn(sunscreen, message)
if (sunscreen.state == 'Closed') then
if (not dryRun) then
sunscreen.switchOn()
domoticz.notify('Sunscreen', message)
end
domoticz.log(message, domoticz.LOG_INFO)
end
end
local function switchOff(sunscreen, message)
if (sunscreen.state == 'Open') then
if (not dryRun) then
sunscreen.switchOff()
domoticz.notify('Sunscreen', message)
end
domoticz.log(message, domoticz.LOG_INFO)
end
end
if (manualOverrideSwitch and domoticz.devices(manualOverrideSwitch).state == 'On') then
domoticz.log('Automatic sunscreen script is manually disabled', domoticz.LOG_DEBUG)
return
end
local sunscreen = domoticz.devices(sunscreenDevice)
-- Sunscreen must always be up during nighttime
if (domoticz.time.isNightTime) then
switchOff(sunscreen, 'Closing sunscreen, It is night')
return
end
-- Check all sensor tresholds and if any exeeded close sunscreen
for sensorType, sensor in pairs(sensors) do
if (sensor['active'] == true) then
local device = domoticz.devices(sensor['device'])
local closeRule = sensor['closeRule']
domoticz.log('Checking sensor: ' .. sensorType, domoticz.LOG_DEBUG)
if (closeRule(device)) then
switchOff(sunscreen, sensorType .. ' treshold exceeded, Sunscreen up')
domoticz.log(sensorType .. ' treshold exceeded', domoticz.LOG_DEBUG)
-- Return early when we exeed any tresholds
return
end
else
domoticz.log('Sensor not active skipping: ' .. sensorType, domoticz.LOG_DEBUG)
end
end
-- All tresholds OK, sunscreen may be lowered
if (sunscreen.lastUpdate.minutesAgo > timeBetweenOpens) then
switchOn(sunscreen, 'Sun is shining, all thresholds OK, lowering sunscreen')
end
end
}

View File

@@ -0,0 +1,119 @@
-- Check the wiki for dzVents
-- remove what you don't need
return {
-- optional active section,
-- when left out the script is active
-- note that you still have to check this script
-- as active in the side panel
active = {
true, -- either true or false, or you can specify a function
--function(domoticz)
-- return true/false
--end
},
-- trigger
-- can be a combination:
on = {
-- device triggers
devices = {
-- scripts is executed if the device that was updated matches with one of these triggers
'device name', -- device name
'abc*', -- triggers for all devices which name begins with abc
258, -- id
},
-- timer riggers
timer = {
-- timer triggers.. if one matches with the current time then the script is executed
'at 13:45',
'at 18:37',
'every 3 minutes on mon,tue,fri at 16:00-15:00',
function(domoticz)
-- return true or false
end
},
-- user variable triggers
variables = {
'myUserVariable'
},
-- security triggers
security = {
domoticz.SECURITY_ARMEDAWAY,
domoticz.SECURITY_ARMEHOME,
},
-- scene triggers
scenes = {
'myScene'
},
-- group triggers
groups = {
'myGroup'
},
-- http http responses
httpResponses = {
'some callback string'
},
-- system events
system = {
'start',
'stop',
'manualBackupFinished',
'dailyBackupFinished',
'hourlyBackupFinished',
'monthlyBackupFinished'
},
customEvents = {
'myCustomEvent'
}
},
-- persistent data
-- see documentation about persistent variables
data = {
myVar = { initial = 5 },
myHistoryVar = { maxItems = 10 },
},
-- custom logging level for this script
logging = {
level = domoticz.LOG_DEBUG,
marker = "Cool script"
},
-- actual event code
-- the second parameter is depending on the trigger
-- when it is a device change, the second parameter is the device object
-- similar for variables, scenes and groups and httpResponses
-- inspect the type like: triggeredItem.isDevice
execute = function(domoticz, triggeredItem, info)
--[[
The domoticz object holds all information about your Domoticz system. E.g.:
local myDevice = domoticz.devices('myDevice')
local myVariable = domoticz.variables('myUserVariable')
local myGroup = domoticz.groups('myGroup')
local myScene = domoticz.scenes('myScene')
The device object is the device that was triggered due to the device in the 'on' section above.
]] --
-- example
if (triggerdItem.active) then -- state == 'On'
triggerdItem.switchOff().afterMin(2) -- if it is a switch
domoticz.notify('Light info', 'The light ' .. triggerdItem.name .. ' will be switched off soon')
end
end
}

View File

@@ -0,0 +1,18 @@
return {
on = {
devices = {},
timer = {},
variables = {},
scenes = {},
groups = {},
security = {},
httpResponses = {},
customEvents = {},
system = {},
},
data = {},
logging = {},
execute = function(domoticz, triggeredItem)
end
}

View File

@@ -0,0 +1,20 @@
return {
on = {
timer = {
'every 5 minutes' -- just an example to trigger the event
},
customEvents = {
'MyEvent' -- event triggered by emitEvent
}
},
data = {},
logging = {},
execute = function(domoticz, triggeredItem)
if (triggeredItem.isCustomEvent) then
domoticz.utils._.print(triggeredItem.data)
else
-- second parameter can be anything, number, string, boolean or table
domoticz.emitEvent('MyEvent', 'Some data')
end
end
}

View File

@@ -0,0 +1,10 @@
return {
on = {
devices = {
'myDevice'
}
},
execute = function(domoticz, device)
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,10 @@
return {
on = {
groups = {
'myGroup'
}
},
execute = function(domoticz, group)
domoticz.log('Group ' .. group.name .. ' was changed', domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,38 @@
return {
on = {
timer = {
'every 5 minutes' -- just an example to trigger the request
},
httpResponses = {
'trigger' -- must match with the callback passed to the openURL command
}
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://somedomain/someAPI?param=1',
method = 'GET',
callback = 'trigger', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.ok) then
if (item.isJSON) then
local someValue = item.json.someValue -- just an example
-- update some device in Domoticz
domoticz.devices('myTextDevice').updateText(someValue)
end
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}

View File

@@ -0,0 +1,10 @@
return {
on = {
scenes = {
'myScene'
}
},
execute = function(domoticz, scene)
domoticz.log('Scene ' .. scene.name .. ' was changed', domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,10 @@
return {
on = {
security = {
domoticz.SECURITY_ARMEDAWAY,
}
},
execute = function(domoticz, security)
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,17 @@
return {
on = {
system = {
'start',
'stop',
'manualBackupFinished',
'dailyBackupFinished',
'hourlyBackupFinished',
'monthlyBackupFinished'
}
},
data = {},
logger = {},
execute = function(domoticz, triggeredItem)
domoticz.log('Domoticz has started')
end
}

View File

@@ -0,0 +1,50 @@
return {
on = {
timer = {
'every minute', -- causes the script to be called every minute
'every other minute', -- minutes: xx:00, xx:02, xx:04, ..., xx:58
'every <xx> minutes', -- starting from xx:00 triggers every xx minutes (0 > xx < 60)
'every hour', -- 00:00, 01:00, ..., 23:00 (24x per 24hrs)
'every other hour', -- 00:00, 02:00, ..., 22:00 (12x per 24hrs)
'every <xx> hours', -- starting from 00:00, triggers every xx hours (0 > xx < 24)
'at 13:45', -- specific time
'at *:45', -- every 45th minute in the hour
'at 15:*', -- every minute between 15:00 and 16:00
'at 12:45-21:15', -- between 12:45 and 21:15. You cannot use '*'!
'at 19:30-08:20', -- between 19:30 and 8:20 then next day
'at 13:45 on mon,tue', -- at 13:45 only on Monday en Tuesday (english)
'every hour on sat', -- you guessed it correctly
'at sunset', -- uses sunset/sunrise info from Domoticz
'at sunrise',
'at sunset on sat,sun',
'xx minutes before sunset',
'xx minutes after sunset',
'xx minutes before sunrise',
'xx minutes after sunrise', -- guess ;-)
'between aa and bb', -- aa/bb can be a time stamp like 15:44
-- aa/bb can be sunrise/sunset
-- aa/bb can be 'xx minutes before/after
-- sunrise/sunset'
'at nighttime', -- between sunset and sunrise
'at daytime', -- between sunrise and sunset
'at civildaytime', -- between civil twilight start and civil twilight end
'at civilnighttime', -- between civil twilight end and civil twilight start
'at daytime on mon,tue', -- between sunrise and sunset only on monday and tuesday
-- or if you want to go really wild:
'at nighttime at 21:32-05:44 every 5 minutes on sat, sun',
'every 10 minutes between 20 minutes before sunset and 30 minutes after sunrise on mon,fri,tue',
-- or just do it yourself:
function(domoticz)
-- you can use domoticz.time to get the current time
-- note that this function is called every minute!
-- custom code that either returns true or false
return true
end,
}
},
execute = function(domoticz, timer)
domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,11 @@
return {
on = {
variables = {
'myUserVariable'
}
},
execute = function(domoticz, variable)
domoticz.log('Variable ' .. variable.name .. ' was changed', domoticz.LOG_INFO)
-- code
end
}

View File

@@ -0,0 +1,16 @@
return {
on = {
devices = {},
timer = {},
variables = {},
scenes = {},
groups = {},
security = {},
httpResponses = {}
},
data = {},
logger = {},
execute = function(domoticz, triggeredItem)
end
}

View File

@@ -0,0 +1,105 @@
-- Check the wiki for dzVents
-- remove what you don't need
return {
-- optional active section,
-- when left out the script is active
-- note that you still have to check this script
-- as active in the side panel
active = {
true, -- either true or false, or you can specify a function
--function(domoticz)
-- return true/false
--end
}
-- trigger
-- can be a combination:
on = {
-- device triggers
devices = {
-- scripts is executed if the device that was updated matches with one of these triggers
'device name', -- device name
'abc*', -- triggers for all devices which name begins with abc
258, -- id
},
-- timer riggers
timer = {
-- timer triggers.. if one matches with the current time then the script is executed
'at 13:45',
'at 18:37',
'every 3 minutes on mon,tue,fri at 16:00-15:00',
function(domoticz)
-- return true or false
end
},
-- user variable triggers
variables = {
'myUserVariable'
},
-- security triggers
security = {
domoticz.SECURITY_ARMEDAWAY,
domoticz.SECURITY_ARMEHOME,
},
-- scene triggers
scenes = {
'myScene'
},
-- group triggers
groups = {
'myGroup'
},
-- http http responses
httpResponses = {
'some callback string'
}
},
-- persistent data
-- see documentation about persistent variables
data = {
myVar = { initial = 5 },
myHistoryVar = { maxItems = 10 },
},
-- custom logging level for this script
logging = {
level = domoticz.LOG_DEBUG,
marker = "Cool script"
},
-- actual event code
-- the second parameter is depending on the trigger
-- when it is a device change, the second parameter is the device object
-- similar for variables, scenes and groups and httpResponses
-- inspect the type like: triggeredItem.isDevice
execute = function(domoticz, triggeredItem, info)
--[[
The domoticz object holds all information about your Domoticz system. E.g.:
local myDevice = domoticz.devices('myDevice')
local myVariable = domoticz.variables('myUserVariable')
local myGroup = domoticz.groups('myGroup')
local myScene = domoticz.scenes('myScene')
The device object is the device that was triggered due to the device in the 'on' section above.
]] --
-- example
if (triggerdItem.active) then -- state == 'On'
triggerdItem.switchOff().afterMin(2) -- if it is a switch
domoticz.notify('Light info', 'The light ' .. triggerdItem.name .. ' will be switched off soon')
end
end
}

View File

@@ -0,0 +1,10 @@
return {
on = {
devices = {
'myDevice'
}
},
execute = function(domoticz, device)
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,18 @@
-- this scripts holds all the globally persistent variables and helper functions
-- see the documentation in the wiki
-- NOTE:
-- THERE CAN BE ONLY ONE global_data SCRIPT in your Domoticz install.
return {
-- global persistent data
data = {
myGlobalVar = { initial = 12 }
},
-- global helper functions
helpers = {
myHelperFunction = function(domoticz)
-- code
end
}
}

View File

@@ -0,0 +1,10 @@
return {
on = {
groups = {
'myGroup'
}
},
execute = function(domoticz, group)
domoticz.log('Group ' .. group.name .. ' was changed', domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,10 @@
return {
on = {
scenes = {
'myScene'
}
},
execute = function(domoticz, scene)
domoticz.log('Scene ' .. scene.name .. ' was changed', domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,10 @@
return {
on = {
security = {
domoticz.SECURITY_ARMEDAWAY,
}
},
execute = function(domoticz, security, info)
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,53 @@
return {
on = {
timer = {
'every minute', -- causes the script to be called every minute
'every other minute', -- minutes: xx:00, xx:02, xx:04, ..., xx:58
'every <xx> minutes', -- starting from xx:00 triggers every xx minutes
-- (0 > xx < 60)
'every hour', -- 00:00, 01:00, ..., 23:00 (24x per 24hrs)
'every other hour', -- 00:00, 02:00, ..., 22:00 (12x per 24hrs)
'every <xx> hours', -- starting from 00:00, triggers every xx
-- hours (0 > xx < 24)
'at 13:45', -- specific time
'at *:45', -- every 45th minute in the hour
'at 15:*', -- every minute between 15:00 and 16:00
'at 12:45-21:15', -- between 12:45 and 21:15. You cannot use '*'!
'at 19:30-08:20', -- between 19:30 and 8:20 then next day
'at 13:45 on mon,tue', -- at 13:45 only on Monday en Tuesday (english)
'every hour on sat', -- you guessed it correctly
'at sunset', -- uses sunset/sunrise info from Domoticz
'at sunrise',
'at sunset on sat,sun',
'xx minutes before sunset',
'xx minutes after sunset',
'xx minutes before sunrise',
'xx minutes after sunrise', -- guess ;-)
'between aa and bb', -- aa/bb can be a time stamp like 15:44
-- aa/bb can be sunrise/sunset
-- aa/bb can be 'xx minutes before/after
-- sunrise/sunset'
'at nighttime', -- between sunset and sunrise
'at daytime', -- between sunrise and sunset
'at civildaytime', -- between civil twilight start and civil twilight end
'at civilnighttime', -- between civil twilight end and civil twilight startœ
'at daytime on mon,tue', -- between sunrise and sunset
-- only on monday and tuesday
-- or if you want to go really wild:
'at nighttime at 21:32-05:44 every 5 minutes on sat, sun',
'every 10 minutes between 20 minutes before sunset and 30 minutes after sunrise on mon,fri,tue',
-- or just do it yourself:
function(domoticz)
-- you can use domoticz.time to get the current time
-- note that this function is called every minute!
-- custom code that either returns true or false
return true
end
},
},
execute = function(domoticz, timer)
domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
end
}

View File

@@ -0,0 +1,11 @@
return {
on = {
variables = {
'myUserVariable'
}
},
execute = function(domoticz, variable)
domoticz.log('Variable ' .. variable.name .. ' was changed', domoticz.LOG_INFO)
-- code
end
}

View File

@@ -0,0 +1,3 @@
This folder will contain scripts that are created inside Domoticz using
the internal script editor. Don't remove this folder and do not edit the scripts in
here as they will be overwritten.

View File

@@ -0,0 +1,3 @@
**Scripts folder**
Place all your scripts in this folder. Only these scripts will be executed by dzVents. See the example folder for some script examples and check the README.md in the root for instructions.

486
dzVents/scripts/livebox.old Normal file
View File

@@ -0,0 +1,486 @@
--[[
Prérequis :
Domoticz v3.8837 or later (dzVents version 2.4 or later)
Sources : https://www.alex-braga.fr/ressources_externe/xdslbox_3.4.10.sh
https://github.com/rene-d/sysbus
https://github.com/NextDom/plugin-livebox/
Livebox 4 stats
https://easydomoticz.com/forum/viewtopic.php?f=17&t=7247
https://github.com/papo-o/domoticz_scripts/new/master/dzVents/scripts/livebox.lua
https://pon.fr/dzvents-toutes-les-infos-de-la-livebox-en-un-seul-script/
-- Authors ----------------------------------------------------------------
V1.0 - Neutrino - Domoticz
V1.1 - Neutrino - Activation/désactivation du WiFi
V1.2 - papoo - Liste des n derniers appels manqués, sans réponse, réussis et surveillance périphériques des connectés/déconnectés
V1.3 - Neutrino - Possibilité de purger le journal d'appels
V1.4 - papoo - Possibilité de rebooter la Livebox
V1.5 - papoo - Correction non mise à jour des devices après RAZ de la liste des appels
V1.6 - papoo - Correction horodatage heures d'appel à GMT+2
V1.7 - papoo - Affichage des noms connus via fichiers de contacts
]]--
-- Variables à modifier ------------------------------------------------
local fetchIntervalMins = 3 -- intervalle de mise à jour.
local adresseLB = '192.168.1.1' --Adresse IP de votre Livebox 4
local password = "jefa6jyu"
local tmpDir = "/var/tmp" --répertoire temporaire, dans l'idéal en RAM
local myOutput=tmpDir.."/Output.txt"
local myCookies=tmpDir.."/Cookies.txt"
-- Domoticz devices
local SyncATM = nil --"Sync ATM" -- Nom du capteur custom Synchro ATM down, nil si non utilisé
local SyncATMup = nil --"Sync ATM up" -- Nom du capteur custom Synchro ATM up, nil si non utilisé
local Attn = nil --"Attn" -- Nom du capteur custom Attenuation de la ligne, nil si non utilisé
local MargedAttn = nil --"Marge d'Attn" -- Nom du capteur custom Marge d'atténuation, nil si non utilisé
local IPWAN = nil --"IP WAN" -- Nom du capteur Text IP WAN, nil si non utilisé
local IPv6WAN = nil --"IPv6 WAN" -- Nom du capteur Text IPv6 WAN, nil si non utilisé
local DernierAppel = "Dernier Appel" -- Nom du capteur Text Dernier Appel, nil si non utilisé
local UptimeLB = nil -- "Uptime Livebox" -- Nom du capteur Text Uptime Livebox, nil si non utilisé
local TransmitBlocks = nil --"TransmitBlocks" -- Nom du capteur Incremental Counter TransmitBlocks, nil si non utilisé
local ReceiveBlocks = nil --"ReceiveBlocks" -- Nom du capteur Incremental Counter ReceiveBlocks, nil si non utilisé
local internet = nil --"Internet" -- Nom du capteur Interrupteur Internet, nil si non utilisé
local VoIP = nil --"VoIP" -- Nom du capteur Interrupteur VoIP, nil si non utilisé
local ServiceTV = nil --"Service TV" -- Nom du capteur Interrupteur Service TV, nil si non utilisé
local wifi24 = nil --"WiFi 2.4" -- Nom du capteur Interrupteur wifi 2.4Ghz, nil si non utilisé
local wifi5 = nil --"WiFi 5" -- Nom du capteur Interrupteur wifi 5Ghz, nil si non utilisé
local missedCall = "Appels manqués" -- Nom du capteur Text appels manqués, nil si non utilisé
local nbMissedCall = 4 -- Nombre d'appels manqués à afficher
local failedCall = "Appels sans réponse" -- Nom du capteur Text appels sans réponse, nil si non utilisé
local nbFailedCall = 4 -- Nombre d'appels sans réponse à afficher
local succeededCall = nil -- "Appels Réussis" -- Nom du capteur Text appels réussis, nil si non utilisé
local nbSucceededCall = 4 -- Nombre d'appels réussis à afficher
local clearCallList = "Effacer liste appels" -- Nom du capteur Interrupteur PushOn clearCallList
local reboot = 1297 -- Nom du capteur Interrupteur PushOn reboot
local devices_livebox_mac_adress = { -- MAC ADDRESS des périphériques à surveiller
"44:6D:6C:A2:68:0C", "8C:1A:BF:49:63:06", "00:25:22:6C:7B:8C",
"44:6D:57:8E:EA:E7", "C8:D0:83:09:22:D3"
}
local fichier_contacts = "/opt/domoticz/scripts/contacts.json"
json = assert(loadfile('/opt/domoticz/scripts/lua/JSON.lua'))()
commandArray = {}
-- SVP, ne rien changer sous cette ligne (sauf pour modifier le logging level)
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
function disp_time(time)
local days = math.floor(time/86400)
local remaining = time % 86400
local hours = math.floor(remaining/3600)
remaining = remaining % 3600
local minutes = math.floor(remaining/60)
remaining = remaining % 60
local seconds = remaining
return string.format("%d:%02d:%02d:%02d",days,hours,minutes,seconds)
end
function traduction(str) -- supprime les accents de la chaîne str
if (str) then
str = string.gsub (str,"missed", "manqué")
str = string.gsub (str,"failed", "échoué")
str = string.gsub (str,"succeeded", "réussi")
end
return (str)
end
function format_date(str) -- supprime les caractères T et Z de la chaîne str et corrige l'heure a GMT +2
if (str) then
_, _, A, M, j, h, m, s = string.find(str, "^(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)Z$")
h = h + 2
str= A.."-"..M.."-"..j.." - "..h..":"..m..":"..s
end
return (str)
end
function ReverseTable(t)
local reversedTable = {}
local itemCount = #t
for k, v in ipairs(t) do
reversedTable[itemCount + 1 - k] = v
end
return reversedTable
end
function json2table(file)
local f = io.open(file, "rb")
if(f == nil) then
return ""
else
local content = f:read("*all")
f:close()
jsonValeur = json:decode(content)
return jsonValeur
end
end
function testActive(domoticz, name, active)
if active == true then
if domoticz.devices(name) then
domoticz.devices(name).switchOn().checkFirst()
end
domoticz.log("Activation de : " .. name, domoticz.LOG_INFO)
else
if domoticz.devices(name) then
domoticz.devices(name).switchOff().checkFirst()
end
domoticz.log("DésActivation de : " .. name, domoticz.LOG_INFO)
end
end
contacts = {}
contacts = json2table(fichier_contacts)
function searchName(contacts, phoneNumber)
-- for index, variable in pairs(contacts) do
-- if variable.Phone == phoneNumber then
-- name = variable.Name
-- end
-- end
-- if name == nil then
name = phoneNumber
-- end
return name
end
local scriptName = 'Livebox'
local scriptVersion = '1.7'
local missedCallList = ""
local failedCallList = ""
local succeededCallList = ""
local patternMacAdresses = string.format("([^%s]+)", ";")
return {
active = true,
logging = {
-- level = domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting
-- level = domoticz.LOG_INFO, -- Seulement un niveau peut être actif; commenter les autres
-- level = domoticz.LOG_ERROR,
-- level = domoticz.LOG_DEBUG,
-- level = domoticz.LOG_MODULE_EXEC_INFO,
marker = scriptName..' '..scriptVersion
},
on = {
timer = {
'every '..tostring(fetchIntervalMins)..' minutes',
},
devices = {wifi5,wifi24,clearCallList,reboot}
},
execute = function(domoticz, item)
--Connexion et récupération du cookies
os.execute("curl -s -o \""..myOutput.."\" -X POST -c \""..myCookies.."\" -H 'Content-Type: application/x-sah-ws-4-call+json' -H 'Authorization: X-Sah-Login' -d \"{\\\"service\\\":\\\"sah.Device.Information\\\",\\\"method\\\":\\\"createContext\\\",\\\"parameters\\\":{\\\"applicationName\\\":\\\"so_sdkut\\\",\\\"username\\\":\\\"admin\\\",\\\"password\\\":\\\""..password.."\\\"}}\" http://"..adresseLB.."/ws > /dev/null")
--Lecture du cookies pour utilisation ultérieure
myContextID = os.capture("tail -n1 \""..myOutput.."\" | sed 's/{\"status\":0,\"data\":{\"contextID\":\"//1'| sed 's/\",//1' | sed 's/\"groups\":\"http,admin//1' | sed 's/\"}}//1'")
domoticz.log('Context : '..myContextID, domoticz.LOG_DEBUG)
if (item.isTimer)then
--Envoi des commandes pour récupérer les informations
MIBs=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.data\\\",\\\"method\\\":\\\"getMIBs\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
domoticz.log('MIBs : '..MIBs, domoticz.LOG_DEBUG)
DSLstats=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.dsl0\\\",\\\"method\\\":\\\"getDSLStats\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
domoticz.log('DSLstats : '..DSLstats, domoticz.LOG_DEBUG)
WAN=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"NMC\\\",\\\"method\\\":\\\"getWANStatus\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
domoticz.log('WAN : '..WAN, domoticz.LOG_DEBUG)
TVstatus=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"NMC.OrangeTV\\\",\\\"method\\\":\\\"getIPTVStatus\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
domoticz.log('TVstatus : '..TVstatus, domoticz.LOG_DEBUG)
voip=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"VoiceService.VoiceApplication\\\",\\\"method\\\":\\\"listTrunks\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
domoticz.log('voip : '..voip, domoticz.LOG_DEBUG)
devicesList=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"Devices\\\",\\\"method\\\":\\\"get\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
domoticz.log('devicesList : '..devicesList, domoticz.LOG_DEBUG)
wifi=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.lan\\\",\\\"method\\\":\\\"getMIBs\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
domoticz.log('wifi : '..wifi, domoticz.LOG_DEBUG)
callList=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"VoiceService.VoiceApplication\\\",\\\"method\\\":\\\"getCallList\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
domoticz.log('callList : '..callList, domoticz.LOG_DEBUG)
--Données de connexion
local lbAPIData = domoticz.utils.fromJSON(MIBs)
if lbAPIData.status == nil or lbAPIData == nil then
domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
else
if SyncATM then domoticz.log('ATM Down: '..lbAPIData.status.dsl.dsl0.DownstreamCurrRate, domoticz.LOG_INFO)
domoticz.devices(SyncATM).updateCustomSensor(lbAPIData.status.dsl.dsl0.DownstreamCurrRate) end
if SyncATMup then domoticz.log('ATM Up: '..lbAPIData.status.dsl.dsl0.UpstreamCurrRate, domoticz.LOG_INFO)
domoticz.devices(SyncATMup).updateCustomSensor(lbAPIData.status.dsl.dsl0.UpstreamCurrRate) end
if Attn then domoticz.log('Attn : '..tostring(lbAPIData.status.dsl.dsl0.DownstreamLineAttenuation/10)..' dB', domoticz.LOG_INFO)
domoticz.devices(Attn).updateCustomSensor(tostring(lbAPIData.status.dsl.dsl0.DownstreamLineAttenuation/10)) end
if MargedAttn then domoticz.log('Marge d\'Attn : '..tostring(lbAPIData.status.dsl.dsl0.DownstreamNoiseMargin/10)..' dB', domoticz.LOG_INFO)
domoticz.devices(MargedAttn).updateCustomSensor(tostring(lbAPIData.status.dsl.dsl0.DownstreamNoiseMargin/10)) end
if UptimeLB then Uptime = disp_time(lbAPIData.status.dhcp.dhcp_data.Uptime)
domoticz.log('Uptime : '..Uptime, domoticz.LOG_INFO)
domoticz.devices(UptimeLB).updateText(Uptime) end
domoticz.log('IP WAN : '..lbAPIData.status.dhcp.dhcp_data.IPAddress, domoticz.LOG_INFO)
if IPWAN and domoticz.devices(IPWAN).text ~= lbAPIData.status.dhcp.dhcp_data.IPAddress then
domoticz.devices(IPWAN).updateText(lbAPIData.status.dhcp.dhcp_data.IPAddress)
end
end
-- Volume de données échangées
local lbAPIDataDSL = domoticz.utils.fromJSON(DSLstats)
if lbAPIDataDSL.status == nil then
domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
else
if TransmitBlocks then domoticz.devices(TransmitBlocks).update(0,lbAPIDataDSL.status.TransmitBlocks) end
if ReceiveBlocks then domoticz.devices(ReceiveBlocks).update(0,lbAPIDataDSL.status.ReceiveBlocks) end
end
-- Etat du lien WAN et IPv6
local lbAPIDataInternet = domoticz.utils.fromJSON(WAN)
if lbAPIDataInternet.status == nil then
domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
else
domoticz.log('Internet : '..lbAPIDataInternet.data.LinkState, domoticz.LOG_INFO)
if internet then
if (lbAPIDataInternet.data.LinkState == 'up' and domoticz.devices(internet).active == false)then
domoticz.devices(internet).switchOn()
elseif (lbAPIDataInternet.data.LinkState ~= 'up' and domoticz.devices(internet).active)then
domoticz.devices(internet).switchOff()
end
end
domoticz.log('IPv6 : '..lbAPIDataInternet.data.IPv6Address, domoticz.LOG_INFO)
if IPv6WAN and domoticz.devices(IPv6WAN).text ~= lbAPIDataInternet.data.IPv6Address then
domoticz.devices(IPv6WAN).updateText(lbAPIDataInternet.data.IPv6Address)
end
end
-- État service VoIP
local lbAPIDataVoIP = domoticz.utils.fromJSON(voip)
if lbAPIDataVoIP.status == nil then
domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
else
domoticz.log('VoIP : '..lbAPIDataVoIP.status[1].trunk_lines[1].status, domoticz.LOG_INFO)
if VoIP then
if (lbAPIDataVoIP.status[1].trunk_lines[1].status == 'Up' and domoticz.devices(VoIP).active == false)then
domoticz.devices(VoIP).switchOn()
elseif (lbAPIDataVoIP.status[1].trunk_lines[1].status ~= 'Up' and domoticz.devices(VoIP).active)then
domoticz.devices(VoIP).switchOff()
end
end
end
--État service TV
local lbAPIDataTV = domoticz.utils.fromJSON(TVstatus)
if lbAPIDataTV.data == nil then
domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
else
domoticz.log('TV : '..lbAPIDataTV.data.IPTVStatus, domoticz.LOG_INFO)
if ServiceTV then
if (lbAPIDataTV.data.IPTVStatus == 'Available' and domoticz.devices(ServiceTV).active == false)then
domoticz.devices(ServiceTV).switchOn()
elseif (lbAPIDataTV.data.IPTVStatus ~= 'Available' and domoticz.devices(ServiceTV).active)then
domoticz.devices(ServiceTV).switchOff()
end
end
end
--État WiFi
local lbAPIDataWifi = domoticz.utils.fromJSON(wifi)
if lbAPIDataWifi.status == nil then
domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
else
domoticz.log('Wifi 2.4 Ghz : '..lbAPIDataWifi.status.wlanvap.wl0.VAPStatus, domoticz.LOG_INFO)
if wifi24 then
if (lbAPIDataWifi.status.wlanvap.wl0.VAPStatus == 'Up' and domoticz.devices(wifi24).active == false)then
domoticz.devices(wifi24).switchOn()
elseif (lbAPIDataWifi.status.wlanvap.wl0.VAPStatus ~= 'Up' and domoticz.devices(wifi24).active)then
domoticz.devices(wifi24).switchOff()
end
end
if wifi5 then
domoticz.log('Wifi 5 Ghz : '..lbAPIDataWifi.status.wlanvap.eth6.VAPStatus, domoticz.LOG_INFO)
if (lbAPIDataWifi.status.wlanvap.eth6.VAPStatus == 'Up' and domoticz.devices(wifi5).active == false)then
domoticz.devices(wifi5).update(1,0)
elseif (lbAPIDataWifi.status.wlanvap.eth6.VAPStatus ~= 'Up' and domoticz.devices(wifi5).active)then
domoticz.devices(wifi5).update(0,0)
end
end
end
--Dernier Appel reçu ou émis
local lbAPIDataCallList = domoticz.utils.fromJSON(callList)
if lbAPIDataCallList.status == nil then
domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
else
domoticz.log('CallList : '..#lbAPIDataCallList.status, domoticz.LOG_INFO)
if (#lbAPIDataCallList.status>0) then
domoticz.log('Dernier Appel : '..lbAPIDataCallList.status[#lbAPIDataCallList.status].remoteNumber, domoticz.LOG_INFO)
domoticz.log('Dernier Appel : '..traduction(lbAPIDataCallList.status[#lbAPIDataCallList.status].callType), domoticz.LOG_INFO)
NumeroEtat = searchName(contacts, lbAPIDataCallList.status[#lbAPIDataCallList.status].remoteNumber) .. " - "..lbAPIDataCallList.status[#lbAPIDataCallList.status].callType
if DernierAppel and domoticz.devices(DernierAppel).text ~= traduction(NumeroEtat) then
domoticz.devices(DernierAppel).updateText(traduction(NumeroEtat))
end
-- x Appels manqués, sans réponse, réussis
for i, call in ipairs(ReverseTable(lbAPIDataCallList.status)) do
if call.callType == "missed" and nbMissedCall > 0 then
domoticz.log(call.remoteNumber .. " " .. traduction(call.callType) .. " " .. format_date(call.startTime), domoticz.LOG_INFO)
missedCallList = missedCallList .. searchName(contacts, call.remoteNumber) .. " - " .. format_date(call.startTime) .. "\n"
nbMissedCall = nbMissedCall - 1
end
if call.callType == "failed" and nbFailedCall > 0 then
domoticz.log(call.remoteNumber .. " " .. traduction(call.callType) .." ".. format_date(call.startTime), domoticz.LOG_INFO)
failedCallList = failedCallList .. searchName(contacts, call.remoteNumber) .." - ".. format_date(call.startTime) .. "\n"
nbFailedCall = nbFailedCall - 1
end
if call.callType == "succeeded" and nbSucceededCall > 0 then
domoticz.log(call.remoteNumber .. " " .. traduction(call.callType) .. " " .. format_date(call.startTime), domoticz.LOG_INFO)
succeededCallList = succeededCallList .. searchName(contacts, call.remoteNumber) .. " - " .. format_date(call.startTime) .. "\n"
nbSucceededCall = nbSucceededCall - 1
end
end
if missedCallList == "" then missedCallList = "Aucun appel à afficher" end
domoticz.log('Appels manqués : \n'..missedCallList, domoticz.LOG_INFO)
if missedCall and domoticz.devices(missedCall).text ~= traduction(missedCallList) then
domoticz.devices(missedCall).updateText(traduction(missedCallList))
end
if failedCallList == "" then failedCallList = "Aucun appel à afficher" end
domoticz.log('Appels sans réponse : \n'..failedCallList, domoticz.LOG_INFO)
if failedCall and domoticz.devices(failedCall).text ~= traduction(failedCallList) then
domoticz.devices(failedCall).updateText(traduction(failedCallList))
end
if succeededCallList == "" then succeededCallList = "Aucun appel à afficher" end
domoticz.log('Appels réussis : \n'..succeededCallList, domoticz.LOG_INFO)
if succeededCall and domoticz.devices(succeededCall).text ~= traduction(succeededCallList) then
domoticz.devices(succeededCall).updateText(traduction(succeededCallList))
end
else
NumeroEtat = "Aucun appel à afficher"
domoticz.log('Dernier Appel : '..NumeroEtat, domoticz.LOG_INFO)
if DernierAppel and domoticz.devices(DernierAppel).text ~= NumeroEtat then
domoticz.devices(DernierAppel).updateText(NumeroEtat)
end
if missedCallList == "" then missedCallList = "Aucun appel à afficher" end
domoticz.log('Appels manqués : \n'..missedCallList, domoticz.LOG_INFO)
if missedCall and domoticz.devices(missedCall).text ~= traduction(missedCallList) then
domoticz.devices(missedCall).updateText(traduction(missedCallList))
end
if failedCallList == "" then failedCallList = "Aucun appel à afficher" end
domoticz.log('Appels sans réponse : \n'..failedCallList, domoticz.LOG_INFO)
if failedCall and domoticz.devices(failedCall).text ~= traduction(failedCallList) then
domoticz.devices(failedCall).updateText(traduction(failedCallList))
end
if succeededCallList == "" then succeededCallList = "Aucun appel à afficher" end
domoticz.log('Appels réussis : \n'..succeededCallList, domoticz.LOG_INFO)
if succeededCall and domoticz.devices(succeededCall).text ~= traduction(succeededCallList) then
domoticz.devices(succeededCall).updateText(traduction(succeededCallList))
end
end
end
local json_peripheriques = domoticz.utils.fromJSON(devicesList)
etatPeripheriques = false
-- Liste des périphériques
for index, peripherique in pairs(json_peripheriques.status) do
domoticz.log("Péripherique " .. index .. " ".. peripherique.Name .." " .. tostring(peripherique.IPAddress) .. " [".. tostring(peripherique.PhysAddress) .."] actif : ".. tostring(peripherique.Active), domoticz.LOG_DEBUG)
for i, mac in pairs(devices_livebox_mac_adress) do
-- mac = string.lower(mac)
if peripherique.PhysAddress == mac then
domoticz.log("Statut du périphérique ".. peripherique.Name .." [" .. mac .. "] => actif:" .. tostring(peripherique.Active), domoticz.LOG_INFO)
if peripherique.Active == true then
etatPeripheriques = true
if domoticz.devices(peripherique.Name) then
domoticz.devices(peripherique.Name).switchOn().checkFirst()
end
domoticz.log("Activation de : " .. peripherique.Name, domoticz.LOG_INFO)
else
if domoticz.devices(peripherique.Name) then
domoticz.devices(peripherique.Name).switchOff().checkFirst()
end
domoticz.log("DésActivation de : " .. peripherique.Name, domoticz.LOG_INFO)
end
end
end
local name = peripherique.Name
local active = peripherique.Active
--debug("Name : "..name.." "..tostring(active))
if (name == "Theo") then
--commandArray['Theo']='On'
testActive(domoticz, 'Theo', active)
end
if (name == "iPhone-de-Jerome") then
--commandArray['moi']='On'
testActive(domoticz, "Moi", active)
end
if (name == "Akhenaton-3") then
testActive(domoticz, "Akhenaton", active)
end
if (name == "Manon") then
--commandArray['Manon']='On'
testActive(domoticz, "Manon", active)
end
if (name == "DomiPro") then
--commandArray['Manon']='On'
testActive(domoticz, "Domi", active)
end
if (name == "octoprint-1") then
testActive(domoticz, "Octoprint", active)
end
if (name == "orangepizero-1") then
testActive(domoticz, "orangepizero", active)
end
if (name == "TeleChambre"
or name == "Volumio" or name == "LibreELEC" or name == "Akhesa"
or name == "SoutiHP" or name == "Hackintosh"
or name == "Recovery") then
testActive(domoticz, name, active)
end
if (name == "RadiateurManon" or name == "RadiateurTheo" or name == "RadiateurBureau"
or name == "RadiateurChambre") then
if active then
-- nothing
else
-- commandArray['SendNotification']='Alerte radiateur '..name..'#Alerte radiateur ne repond pas au ping '..name
end
end
end
else
if(item.name == wifi5)then
os.execute("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..
myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.lan\\\",\\\"method\\\":\\\"setWLANConfig\\\",\\\"parameters\\\":{\\\"mibs\\\":{\\\"penable\\\":{\\\"wifi0_quan\\\":{\\\"PersistentEnable\\\":"..
tostring(item.active)..", \\\"Enable\\\":true}}}}}\" http://"..adresseLB.."/ws &")
domoticz.log("wifi5 "..tostring(item.active),domoticz.LOG_INFO)
elseif(item.name == wifi24)then
os.execute("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..
myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.lan\\\",\\\"method\\\":\\\"setWLANConfig\\\",\\\"parameters\\\":{\\\"mibs\\\":{\\\"penable\\\":{\\\"wifi0_bcm\\\":{\\\"PersistentEnable\\\":"..
tostring(item.active)..", \\\"Enable\\\":true}}}}}\" http://"..adresseLB.."/ws &")
domoticz.log("wifi24 "..tostring(item.active),domoticz.LOG_INFO)
elseif(item.name == clearCallList)then
os.execute("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..
myContextID.."\" -d \"{\\\"service\\\":\\\"VoiceService.VoiceApplication\\\",\\\"method\\\":\\\"clearCallList\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws &")
domoticz.log("clearCallList "..tostring(item.active),domoticz.LOG_INFO)
elseif(item.name == reboot)then
os.execute("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..
myContextID.."\" -d \"{\\\"parameters\\\":{}}\" http://"..adresseLB.."/sysbus/NMC:reboot &")
domoticz.log("reboot "..tostring(item.active),domoticz.LOG_INFO)
end
end
--Déconnexion et suppression des fichiers temporaires
os.execute("curl -s -b "..myCookies.." -X POST http://"..adresseLB.."/logout &")
-- os.execute('rm "'..myCookies..'" "'..myOutput..'" &')
end
}