Page 1 sur 8
1er Script avec weewx
Publié : 09 févr. 2024, 20:31
par salinois
bonjour,
j'espere que c'est le bon endroit pour ça.
j'essaie de parametrer Domoticz pour recupere les dats de ma station Meteo "Weewx".
en regardant sur le Forum , j'ai trouvé un post qui concerne ça.
Le script xml est bien generé par Weewx; mais le script xxx.lua me donne des erreurs.
Quand je regarde dans le script : que veut dire ?
-- Attention au nom du "Dispositif" ,
-- c'est celui que l'on a mis dans la Config (on en choisi un au hasard parmis l'un des dispositifs de notre weewx)
s = otherdevices_lastupdate['Température Salon']
-- returns a date time like 2013-07-11 17:23:12
Dispositif et config "Où"
j'ai suivi ce post:
Weewx & Domoticz sont dans un bateau ...
Message par domcars0 » 22 févr. 2017, 18:45
Logs dans Domoticz:
2024-02-09 20:34:00.568 Error: dzVents: Error: (3.1.8) .../scripts/dzVents/generated_scripts/script_time_weewx.lua:23: attempt to index a nil value (global 'otherdevices_lastupdate')
je suis coincé , je débute...
merci de votre aide
Salinois
Re: 1er Script avec weewx
Publié : 09 févr. 2024, 20:45
par salinois
bon, je cherche

- Capture_2.JPG (41.32 Kio) Consulté 647 fois
Le dispositif est bien "Weewx"; donc je l'ai mis à la ligne 24 : s = otherdevices_lastupdate['Weewx']
mais j'ai l'erreur maintenant
2024-02-09 20:43:00.180 Error: dzVents: Error: (3.1.8) .../scripts/dzVents/generated_scripts/script_time_weewx.lua:24: attempt to index a nil value (global 'otherdevices_lastupdate')
Salinois
Re: 1er Script avec weewx
Publié : 09 févr. 2024, 20:54
par salinois
Voici le script complet; il y a plein de chose que je vais enlever par la suite: Vent, Pluie, Dir Vent....
Code : Tout sélectionner
-- Title: script_device_weewx.lua
-- Date: 10-01-2016
-- this script reads the weewxpws xml file and uploads current data to virtual device
-- format of the xml file =
-- <weewx>
-- <data realtime="temp">8.5<!--outsideTemp--></data>
-- <data realtime="hum">73.2<!--outsideHumidity--></data>
-- <data realtime="inTemp">19.5<!--outsideTemp--></data>
-- <data realtime="inHum">53.2<!--outsideHumidity--></data>
-- <data realtime="barometer">1025.5<!--Pressure--></data>
-- </weewx>
--
--
-- Config
-- local wind_device_idx = 13
-- local rain_device_idx = 11
-- local garden_device_idx = 8
local room_device_idx = 1
-- local aux_device_idx = 14
-- Attention au nom du "Dispositif" ,
-- c'est celui que l'on a mis dans la Config (on en choisi un au hasard parmis l'un des dispositifs de notre weewx)
s = otherdevices_lastupdate['Weewx']
-- returns a date time like 2013-07-11 17:23:12
-- Remplacer 'Vent Jardin' par le nom de votre dispositif anémomètre
-- prev_wind = otherdevices_svalues['Vent Jardin']
-- End Config
commandArray = {}
t1 = os.time()
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
-- ON ne mets à jour que tous les 5 mns
if ( difference < 300 ) then
return commandArray
end
-- ca fonctionne mais c'est parfois un peu long et on dépasse les 10 secondes... on fait donc cela par crontab
-- os.execute('wget http://my-weewx.site.fr/domoticz.xml -O /tmp/domoticz.xml')
-- os.execute('sed s#,#.# /tmp/domoticz.xml > /tmp/domoticz.xml-pre')
local filename = "/etc/weewx/skins/Seasons/domoticz.xml.tmpl"
local line , tempdevice = ''
local temperature,humidity,pressure,inhumidity,intemperature,auxhumidity,auxtemperature,rain,rainrate,wind,winddir,windgust,windchill = 0
local windcomp = 'N'
for line in io.lines(filename) do
if string.find(line,"\"temp\"") then
temperature=tonumber(string.match(line, "%-?%d+.?%d*"))
elseif string.find(line,"\"hum\"") then
humidity=tonumber(string.match(line, "%d+"))
elseif string.find(line,"\"inTemp\"") then
intemperature=tonumber(string.match(line, "%-?%d+.?%d*"))
elseif string.find(line,"\"inHum\"") then
inhumidity=tonumber(string.match(line, "%d+"))
elseif string.find(line,"\"auxTemp\"") then
auxtemperature=tonumber(string.match(line, "%-?%d+.?%d*"))
elseif string.find(line,"\"auxHum\"") then
auxhumidity=tonumber(string.match(line, "%d+"))
elseif string.find(line,"\"barometer\"") then
pressure=tonumber(string.match(line, "%d+"))
elseif string.find(line,"\"rainrate\"") then
rainrate=100 * tonumber(string.match(line, "%d+.?%d*"))
elseif string.find(line,"\"Rain\"") then
rain=tonumber(string.match(line, "%d+.?%d*"))
elseif string.find(line,"\"wind\"") then
wind=tonumber(string.match(line, "%d+"))
elseif string.find(line,"\"Winddir\"") then
winddir=tonumber(string.match(line, "%d+"))
elseif string.find(line,"\"Windgust\"") then
windgust=tonumber(string.match(line, "%d+"))
elseif string.find(line,"\"Windcomp\"") then
windcomp=string.match(line, "Windcomp\">([NESO/A]+)<!--")
elseif string.find(line,"\"WindChill\"") then
windchill=tonumber(string.match(line, "%-?%d+.?%d*"))
end
end
-- Si la vitesse du vent est nulle winddir et windcomp garde la valeur précédente
if ( wind == 0 or wind == nil ) then
winddir,windcomp = prev_wind:match("([^;]+);([^;]+)")
wind = 0
end
-- A l'initialisation du device domoticz on peut avoir des valeurs farfelues
-- if winddir == nil then
winddir = 0
-- end
-- if windcomp =='N/A' then
-- windcomp = 'N'
-- end
-- if windchill == nil then
-- windchill = 0
-- end
-- if windgust== nil then
-- windgust= 0
-- end
-- Conversion de win et wingust (domoticz attend 10 * Winspeed [m/s] -- weewx nous donne Winspeed [km/h]
-- wind = math.ceil(wind / 0.36)
-- windgust = math.ceil(windgust / 0.36)
-- Conditions Salon
if not ( inhumidity == nil or intemperature == nil ) then
tempdevice = room_device_idx..'|1|'..intemperature..';'..inhumidity..';0'
commandArray [1] = {['UpdateDevice'] = tempdevice }
end
-- Meteo Locale idx = 8
if not ( humidity == nil or temperature == nil or pressure == nil ) then
tempdevice = garden_device_idx..'|0|'..temperature..';'..humidity..';0;'..pressure..';0'
commandArray [2] = {['UpdateDevice'] = tempdevice }
end
-- Pluie Locale idx = 11
-- if not ( rainrate == nil or rain == nil ) then
-- tempdevice = rain_device_idx..'|0|'..rainrate..';'..rain
-- commandArray [3] = {['UpdateDevice'] = tempdevice }
-- end
-- Vent Locale idx=13 dir;comp;speed;gust;temp;windchill
-- if not ( temperature == nil ) then
-- tempdevice = wind_device_idx..'|0|'..winddir..';'..windcomp..';'..wind..';'..windgust..';'..temperature..';'..windchill
-- commandArray [4] = {['UpdateDevice'] = tempdevice }
-- end
-- Conditions Aux idx=14 (WC ou Cave)
-- if not ( auxhumidity == nil or auxtemperature == nil ) then
-- tempdevice = aux_device_idx..'|0|'..auxtemperature..';'..auxhumidity..';0'
-- commandArray [5] = {['UpdateDevice'] = tempdevice }
-- end
return commandArray
Re: 1er Script avec weewx
Publié : 10 févr. 2024, 07:35
par denis_brasseur
Il s'agit d'un scrpit Lua, et non DzVents.
Ou as tu placé ton script ?
Il devrait etre sous
/home/pi/domoticz/scripts/lua
et non pas sous
/home/pi/domoticz/scripts/dzVents/scripts
Re: 1er Script avec weewx
Publié : 10 févr. 2024, 09:43
par Keros
salinois a écrit : 09 févr. 2024, 20:45
2024-02-09 20:43:00.180 Error: dzVents: Error: (3.1.8) .../scripts/dzVents/
generated_scripts/script_time_weewx.lua:24: attempt to index a nil value (global 'otherdevices_lastupdate')
@denis_brasseur, il a utilisé le WebUI pour gérer ses scripts et je pense que son script (en LUA) a été créé en sélectionnant DzVents.
@salinois, quand tu as créé ton script en faisant le + en haut, tu as sélectionné LUA ou DzVents ?
Pour ton script, il faut prendre LUA, puis choir le type Time (pour que le trigger Time soit sélectionné).
Re: 1er Script avec weewx
Publié : 10 févr. 2024, 13:16
par Flying Domotic
Attention, si le type est bien "weewx", le nom du dispositif est "Bureau"
Re: 1er Script avec weewx
Publié : 10 févr. 2024, 14:41
par salinois
bonjour à tous,
Manip par le webui:
Ok, donc j'ai effacé le script , il disparait bien du repertoire /home/jeeper/domoticz/scripts/dzVents/generated_scripts/
je refais la meme operation comme le dit Kheros, je sauvegarde mais il n'apparait pas dans le repertoire /home/jeeper/domoticz/scripts/lua/
il n'y a que ceux qui viennent avec l'installation !!!!! par contre dans le Webui, il y est !!!
si je refais la meme chose en choisissant /dzVents/generated_scripts/ "pour tester", il apparait bien dans ce repertoire.
Est-ce un bug ? pour qu'il apparaisse je le créé en ligne de commande !!!
Qu'est-ce que je fais de mal ?
a+
salinois
Re: 1er Script avec weewx
Publié : 10 févr. 2024, 14:48
par Flying Domotic
Il peut être utile de changer :
par :
Re: 1er Script avec weewx
Publié : 10 févr. 2024, 14:50
par salinois
oups,
j'ai oublié de te repondre, j'ai changé weewx par Bureau
Re: 1er Script avec weewx
Publié : 10 févr. 2024, 15:01
par Flying Domotic
Et du coup, c'est quoi l'erreur ?