137 lines
5.7 KiB
Lua
Executable File
137 lines
5.7 KiB
Lua
Executable File
---------------------------------
|
|
-- Script de lecture de calendrier Google.
|
|
-- Actionne un interrupteur ou remplie un capteur virtuel Text
|
|
-- Auteur : Aurelien Neutrino
|
|
-- Date : 29 Novembre 2015
|
|
-- Nécessite un capteur virtuel de type Text
|
|
-- Il faut suivre la source suivante et s'arrêter à la fin de l'étape 1
|
|
-- source :
|
|
-- http://easydomoticz.com/agenda-google-et-domoticz-version-2-partie-1/
|
|
|
|
-- Pour récupérer le code permettant de se connecter
|
|
-- exécuter : sudo gcalcli --cal=Domoticz agenda '00:00' '23:59' --tsv --military
|
|
-- puis coller l'adresse dans un navigateur
|
|
--
|
|
---------------------------------
|
|
require "scripts/lua/functions"
|
|
|
|
commandArray = {}
|
|
--Récupère l'heure et la date actuelle
|
|
time = os.time()
|
|
minutes=tonumber(os.date('%M',time))
|
|
hours=tonumber(os.date('%H',time))
|
|
jour = os.date('%d',time)
|
|
--Nombre de minutes depuis 00:00
|
|
maintenant=tonumber(hours*60+minutes)
|
|
|
|
--idx et nom du capteur Text
|
|
idxText = '203'
|
|
nomText="Agenda"
|
|
|
|
--nom de l'agenda google
|
|
domoticz_cal="Domoticz"
|
|
|
|
--fichier et chemin pour agenda
|
|
repertoire="/home/pi/"
|
|
file="googlecal.txt"
|
|
|
|
-- Toutes les heures, on récupère l'agenda de la journée
|
|
if(maintenant%60==0)then
|
|
options="--tsv --military"
|
|
agenda_start="00:00"
|
|
agenda_end="23:59"
|
|
|
|
-- Agenda Domoticz
|
|
lignecde="sudo gcalcli --cal="..domoticz_cal.." agenda ".."'"..agenda_start.."' '"..agenda_end.."' "..options
|
|
lignecde=lignecde.." > "..repertoire..file.." &"
|
|
os.execute(lignecde)
|
|
|
|
|
|
sleep(1)
|
|
-- Agenda Standard 4/ymDKXAZQtn9azD6vFmUPQ7fJ0jJFeJWOXu___bVKD68
|
|
lignecde="sudo gcalcli --cal=jerome.delacotte@gmail.com agenda '"..agenda_start.."' '"..agenda_end.."' "..options
|
|
lignecde=lignecde.." >> "..repertoire..file.." &"
|
|
os.execute(lignecde)
|
|
|
|
sleep(1)
|
|
-- Agenda Standard 4/ymDKXAZQtn9azD6vFmUPQ7fJ0jJFeJWOXu___bVKD68
|
|
lignecde="sudo gcalcli --cal=jerome.delacotte@vif.fr agenda '"..agenda_start.."' '"..agenda_end.."' "..options
|
|
lignecde=lignecde.." >> "..repertoire..file.." &"
|
|
os.execute(lignecde)
|
|
--end
|
|
|
|
local file = io.open(repertoire..file, "r") -- Ouvre le fichier en mode lecture
|
|
local ligne = {} -- Table pour les lignes du fichier
|
|
|
|
if(file~=nil)then
|
|
--le fichier n'est pas vide
|
|
for line in file:lines() do -- Pour chaque lignes
|
|
table.insert(ligne, line) -- On insère les lignes dans la table
|
|
end
|
|
end
|
|
|
|
for i, v in ipairs(ligne) do -- Lecture de la table des RDV
|
|
dateDebut,heureDebut,minutesDebut,dateFin,heureFin,minutesFin,action = v:match("([^;]+)\t([^;]+):([^;]+)\t([^;]+)\t([^;]+):([^;]+)\t([^;]+)")
|
|
action = action:gsub(" = ","=")
|
|
debutAction = heureDebut*60+minutesDebut
|
|
finAction = heureFin*60+minutesFin
|
|
anneeAction,moisAction,jourAction = dateDebut:match("([^;]+)-([^;]+)-([^;]+)")
|
|
if(action~=nil and action:find("=")~=nil and jourAction == jour)then
|
|
--L'action contient "=", c'est un interrupteur à actionner
|
|
debug("Action : "..action)
|
|
debug(maintenant.." : "..debutAction)
|
|
interrupteur,etat=action:match("([^;]+)=([^;]+)")
|
|
if(otherdevices[interrupteur]~=nil and(etat=='On' or etat=='Off' or etat=='ON' or etat=='OFF')and debutAction==maintenant)then
|
|
--L'interrupteur existe, l'état souhaité est reconnu
|
|
if(etat=='On'or etat=='Off')then
|
|
if(dateDebut~=dateFin)then
|
|
--l'action finit demain
|
|
finAction=finAction+(24*60)
|
|
end
|
|
debug(interrupteur.." passe à "..etat.." pendant "..tostring(finAction-maintenant).." minutes")
|
|
commandArray[interrupteur]=etat.." FOR "..tostring(finAction-maintenant)
|
|
if(otherdevices_svalues[nomText]=='')then
|
|
--Aucun pense-bête actuellement renseigné, on affiche l'action en cours.
|
|
--L'affichage d'un pense-bête est prioritaire sur l'affichage d'un changement d'état
|
|
debug("pense-bête : "..action)
|
|
commandArray['UpdateDevice']=idxText.."|0|"..action
|
|
end
|
|
elseif(etat=='ON')then
|
|
--ON (tout en majuscule) siginifie que l'action n'a pas de fin
|
|
debug(interrupteur.." passe à On")
|
|
commandArray[interrupteur]='On'
|
|
elseif(etat=='OFF')then
|
|
--OFF (tout en majuscule) siginifie que l'action n'a pas de fin
|
|
debug(interrupteur.." passe à Off")
|
|
commandArray[interrupteur]='Off'
|
|
else
|
|
--Etat non reconnu, on force l'interrupteur
|
|
debug(interrupteur.." passe à "..etat)
|
|
commandArray[interrupteur]=etat
|
|
end
|
|
elseif(otherdevices[interrupteur]==nil and debutAction==maintenant)then
|
|
--L'interrupteur n'existe pas, on affiche le pense-bête
|
|
commandArray['UpdateDevice']=idxText.."|0|"..action
|
|
elseif(finAction==maintenant and action == otherdevices_svalues[nomText])then
|
|
--L'action est terminée, on l'efface
|
|
commandArray['UpdateDevice']=idxText.."|0| "
|
|
end
|
|
elseif(action~=nil and action:find("Cong=")~=nil and jourAction == jour)then
|
|
commandArray['Presence']="on"
|
|
else
|
|
debug("###### Action : "..action)
|
|
if (debutAction==maintenant and jourAction == jour) then
|
|
--L'action ne correspond pas à un interrupteur à actionner, c'est donc un pense-bête, on l'affiche pendant la durée souhaitée
|
|
debug("####### Rappel agenda "..action)
|
|
commandArray['UpdateDevice']=idxText.."|0|"..action
|
|
else
|
|
if (finAction==maintenant and action == otherdevices_svalues[nomText]) then
|
|
--L'action est terminée, on l'efface
|
|
debug("####### Fin tâche agenda "..action)
|
|
commandArray['UpdateDevice']=idxText.."|0| "
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return commandArray |