Skip to content

Commit

Permalink
Merge branch 'master' into DRM320
Browse files Browse the repository at this point in the history
  • Loading branch information
destroyedlolo committed Jun 11, 2023
2 parents 2ed6b7f + 142ce73 commit 9f0bcbb
Show file tree
Hide file tree
Showing 78 changed files with 2,499 additions and 340 deletions.
184 changes: 9 additions & 175 deletions Conky/MQTTsub.lua
Original file line number Diff line number Diff line change
@@ -1,199 +1,33 @@
-- Subscribe and expose some MQTT topics
-- (C) Laurent Faillie - 2015 : http://destroyedlolo.info
--
-- 02/06/2021 - Change to luamqtt

local MQTT = require "paho.mqtt"
local mqtt = require "mqtt"

local broker_host = "bpi.chez.moi" -- Where to find the broker
local broker_port = 1883 -- at which port

local topics = { -- Topics to subscribe
EVtsd = {tpc = 'Freebox/DownloadATM'},
EVtsu = {tpc = 'Freebox/UploadATM'},
EMrgd = {tpc = 'Freebox/DownloadMarge'},
EMrgu = {tpc = 'Freebox/UploadMarge'},
EWANd = {tpc = 'Freebox/DownloadWAN'},
EWANu = {tpc = 'Freebox/UploadWAN'},
ETVd = {tpc = 'Freebox/DownloadTV'},
ETVu = {tpc = 'Freebox/UploadTV'},
ELand = {tpc = 'Freebox/DownloadLan'},
ELanu = {tpc = 'Freebox/UploadLan'},

Consomation = {tpc = 'TeleInfo/Consommation/values/PAPP', max=13200}, -- 220v * 60a
Production = {tpc = 'TeleInfo/Production/values/PAPP', max=1900},

vPiscine = {tpc='SondePiscine/Vcc', max=3300, min=2500},
vPoulailler = {tpc='Poulailler/Alim', max=5000, min=4500},
hPoulailler = {tpc='Poulailler/Perchoir/Humidite'},

ups_voltage = {tpc = 'onduleur/input.voltage'},
ups_load = {tpc = 'onduleur/ups.load', max=100},
ups_load_nom = {tpc = 'onduleur/ups.realpower.nominal'},
ups_battery = {tpc = 'onduleur/battery.charge', max=100},

P_Garage = {tpc = 'maison/IO/Porte_Garage'},
P_Cave = {tpc = 'maison/IO/Porte_Cave'},
P_GSud = {tpc = 'maison/IO/Porte_GSud'},
P_GNord = {tpc = 'maison/IO/Porte_GNord'},
B_Poules = {tpc = 'maison/IO/Barriere_Poules'},

Congelo = {tpc = 'maison/Temperature/Congelateur'},
Piscine = {tpc = 'SondePiscine/TempPiscine'},
Poulailler = {tpc = 'Poulailler/Perchoir/Temperature'},
Bureau = {tpc = 'maison/Temperature/Bureau'},
Garage = {tpc = 'maison/Temperature/Garage'},
GarageP = {tpc = 'maison/Temperature/GarageP'},
Comble = {tpc = 'maison/Temperature/Comble'},
Dehors = {tpc = 'maison/Temperature/Dehors'},
Salon = {tpc = 'maison/Temperature/Salon'},
GrenierN= {tpc = 'maison/Temperature/Grenier Nord'},
GrenierS= {tpc = 'maison/Temperature/Grenier Sud'},
ChJoris= {tpc = 'maison/Temperature/Chambre Joris'},
ChOceane= {tpc = 'maison/Temperature/Chambre Oceane'}
}
local broker_host = "torchwood.local" -- Where to find the broker [:port]

---- End of configurable area ----
os.setlocale('C') -- otherwise, fail with locale where ',' is the decimal separator (FR)

-- Unfortunately, paho lib doesn't like keyed tables
-- so we have to build a temporary collection
ttopics = {}
rtopics = {}
for k,v in pairs( topics ) do
ttopics[ #ttopics + 1 ] = v.tpc
rtopics[ v.tpc ] = k
end

function callback(
topic, -- string
message) -- string

-- debug only
-- print("Topic: " .. topic .. ", message: '" .. message .. "'")

_G[ rtopics[ topic ] ] = message
end

-- Connect to the broker and subscribe to topics
-- https://github.com/xHasKx/luamqtt/blob/master/examples/sync.lua
function conky_init()
brkc = MQTT.client.create( broker_host, broker_port, callback)
brkc:connect( conky_parse( '$nodename' ) ..'_' .. os.getenv('USER') )
brkc:subscribe( ttopics )
client = mqtt.client{ uri = broker_host, clean = true }
print("Connected")

end

-- leaving, doing some cleaning
function conky_cleanup()
brkc:unsubscribe(ttopics)
brkc:destroy()
end

function conky_displayvar( var )
if not _G[ var ] then
return '????'
else
return tostring(_G[ var ])
end
end

function conky_displayAccess( var )
if not _G[ var ] then
return '????'
else
if _G[ var ] == "Ouverte" then
ret = "${color red}"
else
ret = "${color}"
end
return ret .. _G[ var ]
end
end

function conky_displayvarCongelo( var, unite )
if not _G[ var ] then
return '????'
else
local ret = ""
if tonumber(_G[ var ]) > -10 then
ret = "${color red}"
else
ret = "${color}"
end
return ret..tostring(_G[ var ]).."${color grey} "..unite
end
end


function conky_displayvarU( var, unite )
if not _G[ var ] then
return '????'
else
return tostring(_G[ var ]).."${color grey} "..unite
end
end

function conky_getConso( )
return Consomation
end

function conky_getProd( )
return Production
end

function conky_getprc( var )
if not _G[ var ] then
return 0
end

if not topics[ var ].min then
return 100*_G[ var ]/topics[ var ].max
else
local t = _G[ var ] - topics[ var ].min
local delta = topics[ var ].max - topics[ var ].min
if t < 0 then
return 0
else
return 100 * t / delta
end
end
end

function conky_getCharge( )
if not ups_load_nom or not ups_load then
return '????'
else
return ups_load * ups_load_nom / 100
end
end

function conky_getVPiscine( )
if not vPiscine then
return '????'
else
return vPiscine / 1000
end
end

function conky_getVPoulailler( )
if not vPoulailler then
return '????'
else
return vPoulailler / 1000
end
end

function conky_getHPoulailler( )
if not hPoulailler then
return '????'
else
return hPoulailler
end
end

function conky_handlebroker() -- loop to handle messages
if not brkc then -- As it seems lua_draw_hook_pre is called before init :(
return
end

local err = brkc:handler()
mqtt.run_sync(client)

if err then
print('*E*',err);
Expand Down
50 changes: 4 additions & 46 deletions Conky/configMQTT
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
conky.config = {
--configuration pour Conky écoutant un broker MQTT

lua_load = '/usr/local/share/conky/MQTTsub.lua',
-- lua_load = '/usr/local/share/conky/MQTTsub.lua',
lua_load = './MQTTsub.lua',

lua_startup_hook = 'init',
lua_shutdown_hook = 'cleanup',
lua_draw_hook_pre = 'handlebroker',
Expand Down Expand Up @@ -37,6 +39,7 @@ conky.config = {
own_window_type = 'normal',
own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
own_window_transparent = true,
own_window_argb_visual = true,
--own_window_transparent no
--own_window_argb_value 30
stippled_borders = 0,
Expand Down Expand Up @@ -76,49 +79,4 @@ ${color grey}\1 : ${lua_parse displayAccess \2 \3}]],
conky.text = [[
${color Green}Températures maison${offset 8}${color8}${voffset -2}${hr}

${template0 Comble Comble °C} ${template0 Dehors Dehors °C}
${template0 Gr_Sud GrenierS °C} ${template0 Gr_Nord GrenierN °C}
${template0 Oceane ChOceane °C} ${template0 Joris ChJoris °C}
${template0 Salon Salon °C} ${template0 Bureau Bureau °C}
${template0 Garage Garage °C} ${template0 Prt_Grg GarageP °C}

${template3 Congelo Congelo °C}

${color Green}Poulailler${offset 8}${color8}${voffset -2}${hr}

${template0 Température Poulailler °C} Humidité : ${color}${lua_parse getHPoulailler}
${color grey}Batterie : ${color}${lua_parse getVPoulailler} V ${lua_bar getprc vPoulailler}

${color Green}Piscine${offset 8}${color8}${voffset -2}${hr}

${template0 Température Piscine °C}
${color grey}Batterie : ${color}${lua_parse getVPiscine} V ${lua_bar getprc vPiscine}

${color Green}Portes${offset 8}${color8}${voffset -2}${hr}

${color grey}Grenier ${template4 Sud P_GSud} ${template4 Nord P_GNord}
${template4 Cave P_Cave} ${template4 Garage P_Garage}
${template4 Barriere_Poules B_Poules}

${color Green}Electricité${offset 8}${color8}${voffset -2}${hr}
#${lua_graph getConso 20, 00aa00 aa0000 -t}
# ${voffset -19}${template0 Consomation Consomation VA}

${template0 Consomation Consomation VA} ${lua_bar getprc Consomation}
#${lua_graph getProd 20, 00aa00 aa0000 -t}
# ${voffset -19}${template0 Production Production VA}
${template0 Production Production VA} ${lua_bar getprc Production}

${color Green}Onduleur${offset 8}${color8}${voffset -2}${hr}

${template0 Réseau ups_voltage V}
Charge : ${color}${lua_parse getCharge} W ${lua_bar getprc ups_load}

${color Green}Internet${offset 8}${color8}${voffset -2}${hr}

${template1 Vitesse EVtsd EVtsu Kb}
${template1 Marge EMrgd EMrgu db}
${template1 Internet EWANd EWANu Ko}
${template1 TV ETVd ETVu Ko}
${template1 Lan ELand ELanu Ko}
]];
32 changes: 19 additions & 13 deletions SeleniteCurses/Automatisme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ function initAuto()
SuiviSol:attrset( SelCurses.CharAttrConst('BOLD') )
updateSuiviSol()

wmdSub:Move(2,5)
genTitre(wmdSub, 'Invoie &separateur de logs')

wmdSub:refresh()
genMenu()
end

function popupSaison(Brk, topic)
local w,h = wmdSub:GetSize()
local popup = wmdSub:DerWin((w-15)/2,2, 18,5)
local popup = wmdSub:DerWin( math.floor((w-15)/2), 2, 18,5)

genTitre(popup, "\n &Intersaison\n")
genTitre(popup, " &Ete\n")
Expand All @@ -73,7 +76,10 @@ end

function keyAuto(Brk, c,cn)
if c == 'a' then
popupSaison(Brk,'Majordome/Saison')
popupSaison(Brk, MAJORDOME..'/Saison')
elseif c == 's' then
Brk:Publish(MAJORDOME..'/Log/Information', '--------------------------')
Brk:Publish(MARCEL..'/Log/Information', '--------------------------')
end

initAuto()
Expand All @@ -86,31 +92,31 @@ swinLst['M'] = { titre="&Majordome", func=initAuto, key=keyAuto, close=FermeAuto
function updateSaison()
if Mode == 'M' then
Saison:clear()
Saison:print(SelShared.Get('Majordome/Saison'))
Saison:print(SelShared.Get(MAJORDOME..'/Saison'))
Saison:refresh()
end
end

function updateSaisonH()
if Mode == 'M' then
SaisonH:clear()
SaisonH:print(SelShared.Get('Majordome/Saison/Hier'))
SaisonH:print(SelShared.Get(MAJORDOME..'/Saison/Hier'))
SaisonH:refresh()
end
end

function updateModeR()
if Mode == 'M' then
ModeR:clear()
ModeR:print(SelShared.Get('Majordome/Mode'))
ModeR:print(SelShared.Get(MAJORDOME..'/Mode'))
ModeR:refresh()
end
end

function updateSuiviSol()
if Mode == 'M' then
SuiviSol:clear()
local r = SelShared.Get('Majordome/Traces/SuiviCoucherSoleil')
local r = SelShared.Get(MAJORDOME..'/Traces/SuiviCoucherSoleil')
if r ~= nil then
if r:byte() == 70 then -- 'F'
local h,m,hd,md = r:match( "(%d+):(%d+);(%d+):(%d+)" )
Expand All @@ -128,16 +134,16 @@ function updateSuiviSol()
end

local ltopics = {
{ topic = 'Majordome/Saison', trigger=updateSaison, trigger_once=true },
{ topic = 'Majordome/Saison/Hier', trigger=updateSaisonH, trigger_once=true },
{ topic = 'Majordome/Mode', trigger=updateModeR, trigger_once=true },
{ topic = 'Majordome/Traces/SuiviCoucherSoleil', trigger=updateSuiviSol, trigger_once=true },
{ topic = MAJORDOME..'/Saison', trigger=updateSaison, trigger_once=true },
{ topic = MAJORDOME..'/Saison/Hier', trigger=updateSaisonH, trigger_once=true },
{ topic = MAJORDOME..'/Mode', trigger=updateModeR, trigger_once=true },
{ topic = MAJORDOME..'/Traces/SuiviCoucherSoleil', trigger=updateSuiviSol, trigger_once=true },
}
TableMerge( Topics, ltopics)

-- Valeurs par défauts (pour éviter un crash si elle ne sont pas définies)

SelShared.Set('Majordome/Saison', '?')
SelShared.Set('Majordome/Saison/Hier', '?')
SelShared.Set('Majordome/Mode', '?')
SelShared.Set(MAJORDOME..'/Saison', '?')
SelShared.Set(MAJORDOME..'/Saison/Hier', '?')
SelShared.Set(MAJORDOME..'/Mode', '?')

Loading

0 comments on commit 9f0bcbb

Please sign in to comment.