My name is Steef, and I am exploring the (endless) possibilities of the Domoticz workaround.
I have Domoticz running on a Raspberry Pi 3b, running on Raspbian.
Because I would really like to receive detailed weather information, I am trying to follow a nice how-to I found on the internet: https://ehoco.nl/domoticz-weerstation/ (The how-to is in Dutch).
I followed the how-to, but somehow, I receive an error on the following line:
Code: Select all
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[device]..'|'..tostring(nvalue)..'|'..tostring(svalues)}
The complete script is mentioned below. I am trying to understand the .lua language, but it is new to me, and can not find the error.
Is there anyone who can help me with this problem? many thanks!
Code: Select all
--[[ WEERSTATIONS:
Amsterdam = 36 Groningen = 13 Oost-Groninigen = 31 Vlissingen = 44
Arnhem = 2 Hoek van Holland = 17 Oost-Overijssel = 12 Voorschoten = 46
Berkhout = 3 Hoogeveen = 18 Rotterdam = 33 Wadden = 19
Den Helder = 6 Leeuwarden = 26 Utrecht = 5 Weert = 8
Eindhoven = 7 Lelystad = 27 Terneuzen = 47 West-Friesland = 38
Gilze Rijen = 10 Maastricht = 29 Twente = 41 West-Utrecht = 28
Goes = 11 Noord-Groninigen = 24 Uden = 45 Woensdrecht = 50
Gorinchem = 16 Noordoostpolder = 30 Venlo = 1 Zwolle = 15
--]]
--------------------------------
---------- SETTINGS ------------
--------------------------------
local domo_ip = "lokaal IP plus poort" -- IP adres van Domoticz, inclusief poort
local weerstation = 15 -- Kies je weerstation naar keuze
local api_key = "API key" -- Darksky secret key
local debug = 0 -- 0 = no debug, 1 = debug
local language = "nl" -- ar: Arabic, az: Azerbaijani, be: Belarusian, bg: Bulgarian, bs: Bosnian, ca: Catalan, cs: Czech, da: Danish,
-- de: German, el: Greek, en: English, es: Spanish, et: Estonian, fi: Finnish, fr: French, he: Hebrew, hr: Croatian,
-- hu: Hungarian, id: Indonesian, is: Icelandic, it: Italian, ja: Japanese, ka: Georgian, ko: Korean, kw: Cornish,
-- lv: Latvian, nb: Norwegian Bokmål, nl: Dutch, no: Norwegian Bokmål (alias for nb), pl: Polish, pt: Portuguese,
-- ro: Romanian, ru: Russian, sk: Slovak, sl: Slovenian, sr: Serbian, sv: Swedish, tet: Tetum, tr: Turkish,
-- uk: Ukrainian, x-pig-latin: Igpay Atinlay, zh: simplified Chinese, zh-tw: traditional Chinese
local dev_TempGround = "GrondTemperatuur" -- Temperature sensor
local dev_TextTomorrow = "Verwachting morgen" -- Text sensor
local dev_LongText = "Uitgebreide verwachting" -- Text sensor
local dev_DewPoint = "Dauwpunt" -- Temperature sensor
local dev_CloudCover = "Bewolkingsgraad" -- Percentage sensor
local dev_UV = "UV" -- UV sensor
local dev_Ozone = "Ozone" -- Custom sensor with axis "DU"
--Functie devices updaten
if commandArray == nil then commandArray = {} end
function UpdateDev(device,nvalue,svalues)
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[device]..'|'..tostring(nvalue)..'|'..tostring(svalues)}
end
-- Functie afronding
function round(num, dec)
if num == 0 then
return 0
else
local mult = 10^(dec or 0)
return math.floor(num * mult + 0.5) / mult
end
end
--------------------------------------------------
----- ######## Buienradar API Data call ######## -----
--------------------------------------------------
time = os.date("*t")
if ((time.min+2)%5)==0 then -- Script loopt iedere 5 minuten (bv. 11.03, 11.08, 11.13, 11.18, etc.
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen('curl "https://api.buienradar.nl/data/public/2.0/jsonfeed"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
-- Convert the json to a LUA table
if jsonData.actual.stationmeasurements[ weerstation ] ~= nil then -- this sometimes happens around midnight
val_TempGround = jsonData.actual.stationmeasurements[ weerstation ].groundtemperature
val_WeatherTomorrow = jsonData.forecast.fivedayforecast[1].weatherdescription
val_SunChanceTomorrow = jsonData.forecast.fivedayforecast[1].sunChance
val_RainChanceTomorrow = jsonData.forecast.fivedayforecast[1].rainChance
val_RainMinimum = jsonData.forecast.fivedayforecast[1].mmRainMin
val_RainMaximum = jsonData.forecast.fivedayforecast[1].mmRainMax
val_WindDirectionTomorrow = jsonData.forecast.fivedayforecast[1].windDirection
val_WindSpeedTomorrow = jsonData.forecast.fivedayforecast[1].wind
val_TempTomorrowMinMin = jsonData.forecast.fivedayforecast[1].mintemperatureMin --minimale minimumtemperatuur
val_TempTomorrowMaxMin = jsonData.forecast.fivedayforecast[1].mintemperatureMax --maximale minimumtemperatuur
val_TempTomorrowMinMax = jsonData.forecast.fivedayforecast[1].maxtemperatureMin --minimale maximumtemperatuur
val_TempTomorrowMaxMax = jsonData.forecast.fivedayforecast[1].maxtemperatureMax --maximale maximumtemperatuur
end
--Min/Max. temperatuur bepalen
if val_TempTomorrowMinMin == val_TempTomorrowMaxMin then TempMinimum = val_TempTomorrowMinMin
else TempMinimum = val_TempTomorrowMinMin.." - "..val_TempTomorrowMaxMin end
if val_TempTomorrowMinMax == val_TempTomorrowMaxMax then TempMaximum = val_TempTomorrowMinMax
else TempMaximum = val_TempTomorrowMinMax.." - "..val_TempTomorrowMaxMax
end
--Regenhoeveeldheid bepalen
if val_RainMinimum == val_RainMaximum then RainIntensity = val_RainMinimum
else RainIntensity = val_RainMinimum.." - "..val_RainMaximum end
-- Windrichting tekst bepalen
if val_WindDirectionTomorrow == "z" or val_WindDirectionTomorrow == "Z" then WindDirectionTomorrow = " het zuiden"
elseif val_WindDirectionTomorrow == "zw" or val_WindDirectionTomorrow == "ZW" then WindDirectionTomorrow = "het zuidwesten"
elseif val_WindDirectionTomorrow == "zo" or val_WindDirectionTomorrow == "ZO" then WindDirectionTomorrow = "het zuidoosten"
elseif val_WindDirectionTomorrow == "w" or val_WindDirectionTomorrow == "W" then WindDirectionTomorrow = "het westen"
elseif val_WindDirectionTomorrow == "nw" or val_WindDirectionTomorrow == "NW" then WindDirectionTomorrow = "het noordwesten"
elseif val_WindDirectionTomorrow == "n" or val_WindDirectionTomorrow == "N" then WindDirectionTomorrow = "het noorden"
elseif val_WindDirectionTomorrow == "no" or val_WindDirectionTomorrow == "NO" then WindDirectionTomorrow = " het noordoosten"
elseif val_WindDirectionTomorrow == "o" or val_WindDirectionTomorrow == "O" then WindDirectionTomorrow = "het oosten"
else WindDirectionTomorrow = "variabele richtingen" end
--Voorspellingen
forecast=val_WeatherTomorrow.. "\n " .."\n".. "Komende nacht daalt de temperatuur naar "..TempMinimum.." °C. Morgen overdag wordt morgen maximaal "..TempMaximum.. " °C. Er is morgen "..val_SunChanceTomorrow.." % kans op zon en "..val_RainChanceTomorrow.." % kans op neerslag ("..RainIntensity.." mm). De wind komt uit "..WindDirectionTomorrow.." en zal kracht "..val_WindSpeedTomorrow.." Bft hebben." .."\n " .."\n "
if otherdevices_svalues[dev_TextTomorrow] ~= forecast then UpdateDev(dev_TextTomorrow,0,forecast) end
-- Updating domoticz devices
UpdateDev(dev_TempGround,0,val_TempGround)
if debug==1 then
print ("Temperatuur grond: "..val_TempGround.." °C")
end
end
---------------------------------------
-- ######## Darksy API call ######## --
---------------------------------------
if ((time.min+2)%5)==0 then -- Script loopt iedere 5 minuten (bv. 11.03, 11.08, 11.13, 11.18, etc.
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen('curl "http://'..domo_ip..'/json.htm?type=settings"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
-- Convert the json to a LUA table
lat = jsonData.Location.Latitude
lon = jsonData.Location.Longitude
local coord = lat..","..lon
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen('curl "https://api.darksky.net/forecast/'..api_key..'/'..coord..'?lang='..language..'&units=si&exclude=hourly,flags"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
-- Convert the json to a LUA table
if jsonData ~= nil then -- this sometimes happens around midnight
val_UV = jsonData.currently.uvIndex
val_Ozone = jsonData.currently.ozone
val_DewPoint = round(jsonData.currently.dewPoint,1)
val_CloudCover = jsonData.currently.cloudCover*100
end
if debug==1 then
print("Bewolkingsgraad : "..val_CloudCover.. " %")
print("UV-kracht :"..val_UV)
print("Ozone : De ozone-waarde is "..val_Ozone)
print("Dauwpunt : "..val_DewPoint.. " °C")
end
-- Domoticz devices updaten
UpdateDev(dev_CloudCover,0,val_CloudCover)
UpdateDev(dev_DewPoint,0,val_DewPoint)
UpdateDev(dev_UV,0,val_UV..";0")
UpdateDev(dev_Ozone,0,val_Ozone)
if debug==1 then
print ("Dauwpunt: "..val_DewPoint.." °C")
print ("Bewolkingsgraad: "..val_CloudCover.." %")
print ("UV-Index: "..val_UV)
print ("Ozone: "..val_Ozone)
end
end
-------------------------------------------------------
-- ######## Buienradar Verwachting API call ######## --
-------------------------------------------------------
if ((time.min+2)%30)==0 then -- Script loopt iedere 30 minuten (bv. 11.28, 11.58, 12.28, 12.58, etc.
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen('curl "https://api.buienradar.nl/data/public/1.1/jsonfeed"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
-- Convert the json to a LUA table
val_LongText = jsonData.buienradarnl.weergegevens.verwachting_vandaag.titel .."\n " .."\n ".. jsonData.buienradarnl.weergegevens.verwachting_vandaag.tekst .."\n " .."\n"
if debug==1 then
print ("Uitgebreid: "..val_LongText)
end
if otherdevices_svalues[dev_LongText] ~= val_LongText then UpdateDev(dev_LongText,0,val_LongText) end
end