Voici le script que j'ai fait. Il est modifiable selon vos besoins / équipements.
C'est mon premier "vrai script" alors soyez indulgent il n'est pas parfait mais fonctionne bien pour moi.
Merci au passage à jmleglise et Vil1driver pour leur aide !
Code : Tout sélectionner
--[[
auteur : stephdes
version : 1.0
MAJ : 12/12/2016
Principe :
Si mon "réveil" est activé, tous les matins à 7H une annonce avec température, météo, fête du jour... est diffusée sur un HP bluetooth de ma pièce de vie"
]]--
commandArray = {}
local timeNow= os.date("*t")
local curl = 'C:\\curl\\bin\\curl.exe ' --METTRE ICI LE CHEMIN DE VOTRE CURL
local saint = otherdevices_svalues['Fête du jour'] -- METTRE ICI VOTRE DEVICE "fête du jour" si vous en avez un
-- ############# REMISE A ZERO DE LA VARIABLE "BONJOUR" ENTRE 6H et 7H (la variable doit être de type chaîne) #################
if (timeNow.hour >=5 and timeNow.hour <6) then
commandArray['Variable:bonjour'] = tostring (0)
end
-- ############# CONDITIONS NECESSAIRES A L'EXECUTION DU SCRIPT #################
if (otherdevices['Reveil'] == 'On' and
timeNow.hour >=7 and
uservariables["bonjour"] == '0')
then
-- ############# DEMARRAGE DE LA COMPOSITION DU MESSAGE #################
local sentence="Bonjour ! Nous sommes le " ..(os.date("%A")).. " " ..(os.date("%d")).. " " .. os.date("%B")
-- ############# PASSAGE DU JOUR ET DU MOIS EN FRANCAIS #################
local d = {
["Monday"] = " Lundi ",
["Tuesday"] = " Mardi ",
["Wednesday"] = " Mercredi ",
["Thursday"] = " Jeudi ",
["Friday"] = " Vendredi ",
["Saturday"] = " Samedi ",
["Sunday"] = " Dimanche ",
["01"] = " premier ",
["02"] = " deux ",
["03"] = " trois ",
["04"] = " quatre ",
["05"] = " cinq ",
["06"] = " six ",
["07"] = " sept ",
["08"] = " huit ",
["09"] = " neuf ",
["January"] = " Janvier ",
["February"] = " Février ",
["March"] = " Mars ",
["April"] = " Avril ",
["May"] = " Mai ",
["June"] = " Juin ",
["July"] = " Juillet ",
["August"] = " Août ",
["September"] = " Septembre ",
["October"] = " Octobre ",
["November"] = " Novembre ",
["December"] = " Décembre " }
for k, v in pairs (d) do
sentence = string.gsub(sentence, k, v)
end
-- ############# PROGRAMME D'ENCODAGE DU TEXTE POUR LE TTS #################
function url_encode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
-- ############# TEMPERATURE ET METEO #################
if (otherdevices['Température extérieure']) then --METTRE ICI VOTRE DEVICE DE TEMPERATURE
temperature1, hygro1, etat1= otherdevices_svalues['Température extérieure']:match("([^;]+);([^;]+)")
-- print("TEMP:"..temperature1);
-- print("HUM:"..hygro1);
end
sentence=sentence..". La température extérieure est de "..temperature1.." degré et le taux d'humidité est de "..hygro1.." pourcent. "
json = (loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\JSON.lua")() --METTRE ICI LE CHEMIN DU JSON
local city = "xxx"
local wuAPIkey = "xxx"
local file=assert(io.popen(curl.. 'http://api.wunderground.com/api/'..wuAPIkey..'/forecast/lang:FR/q/France/'..city..'.json'))
local raw = file:read('*all')
file:close()
local jsonForecast = json:decode(raw)
prevision=jsonForecast.forecast.txt_forecast.forecastday[1].fcttext_metric -- Prévision complète
-- prevision=jsonForecast.forecast.simpleforecast.forecastday[1].conditions -- Prévision rapide
local t = {
["ºC"] = "degré",
[" ENE "] = " Est Nord Est ",
[" NNE "] = " Nord Nord Est ",
[" NE "] = " Nord Est ",
[" N "] = " Nord ",
[" NNO "] = " Nord Nord Ouest ",
[" NO "] = " Nord Ouest ",
[" SSE "] = " Sud Sud Est ",
[" SE "] = " Sud Est ",
[" S "] = " Sud ",
[" SSO "] = " Sud Sud Ouest ",
[" SO "] = " Sud Ouest ",
[" O "] = " Ouest ",
[" E "] = " Est ",
["km/h"] = " kilomètre heure" }
for k, v in pairs (t) do
prevision = string.gsub(prevision, k, v)
end
sentence=sentence.."Le temps de la journée sera "..prevision
-- ############# AJOUT RISQUE DE GIVRE #################
if (otherdevices_svalues['Risque de givre'])=='Risque de givre' then
sentence=sentence.." Il y a peut etre du givre, soyez prudent."
elseif (otherdevices_svalues['Risque de givre'])=='Présence de givre !' then
sentence=sentence.." Attention il y a du givre, soyez très prudent!"
end
-- ############# AJOUT DU SAINT DU JOUR #################
sentence=sentence..". Aujourd'hui, nous fêtons les "..saint.." . "
-- ############# AJOUT JOUR DES POUBELLES #################
numOfDay=os.date("%w")
if (numOfDay == '1') then
sentence=sentence.." Les poubelles sont ramassées ce matin."
end
-- ############# ENCODAGE DU TTS #################
sentence = url_encode(sentence)
-- ############# SORTIE DU TEXTE #################
--print (sentence)
commandArray['OpenURL']="http://localhost:8888/?tts="..sentence..""
-- ############# PASSAGE DE LA VARIABLE BONJOUR A 1 POUR N'AVOIR LE MESSAGE QU'UNE SEULE FOIS PAR JOUR #################
commandArray['Variable:bonjour'] = tostring (1)
end
return commandArray