[DzVents] DarkSky et probabilité de pluie

Vous avez créé un script LUA dont vous êtes fier, un .sh génial, un programme Python hors du commun, un Tuto, c'est ici que vous pouvez les partager.
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: DZVents : DarkSky et probabilité de pluie

Message par papoo »

McFlyPartages a écrit : 01 janv. 2020, 16:02

Je ne parviens par a ouvrir sqlite3 sur mon rapsberry en sudo non plus. est ce qu'il y a une manip particulière ?
il faut l'installer si il ne l'est pas

Code : Tout sélectionner

	
sudo apt-get install sqlite3 libsqlite3-dev
McFlyPartages a écrit : 01 janv. 2020, 16:02 Petite question.
Si je change le sélecteur en manuel il change l’icône ?
oui, essais de rafraîchir ton navigateur au cas ou il ne prenne pas la modif avec Ctrl + F5
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
McFlyPartages
Messages : 28
Inscription : 28 nov. 2019, 20:50
Localisation : Finistere
Contact :

Re: DZVents : DarkSky et probabilité de pluie

Message par McFlyPartages »

papoo a écrit : 01 janv. 2020, 16:12
McFlyPartages a écrit : 01 janv. 2020, 16:02

Je ne parviens par a ouvrir sqlite3 sur mon rapsberry en sudo non plus. est ce qu'il y a une manip particulière ?
il faut l'installer si il ne l'est pas

Code : Tout sélectionner

	
sudo apt-get install sqlite3 libsqlite3-dev
McFlyPartages a écrit : 01 janv. 2020, 16:02 Petite question.
Si je change le sélecteur en manuel il change l’icône ?
oui, essais de rafraîchir ton navigateur au cas ou il ne prenne pas la modif avec Ctrl + F5
Désolé je croyez qu'il y était par défaut

C'est bon j'ai bien de 110 a 117 ce que j'ai mis dans le script.
Domoticz Bêta v4.11670
Xiaomi, Sonoff, Blitzwolf, Harmony, Broadlink, Amazon, Ikea, Yeelight, Roborock, Aqara, Nut, Zigate, RfLink, MySensors, ESPEasy, Etc

Site Web : https://mcflypartages.fr
Chaine YouTube : https://youtube.com/mcflypartages
McFlyPartages
Messages : 28
Inscription : 28 nov. 2019, 20:50
Localisation : Finistere
Contact :

Re: DZVents : DarkSky et probabilité de pluie

Message par McFlyPartages »

Dans le doute je me suis connecté d'un autre PC et d'un smartphone mais idem donc deja ce n'est pas un probleme de cache.

Comme dit plus haut mes icônes sont bien 110 a 117.

Il y a peut etre des news du coté des logs.

Code : Tout sélectionner

 2020-01-01 16:33:01.687 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-01-01 16:33:02.008 Status: dzVents: Info: Handling events for: "Lune", value: "Premier croissant"
2020-01-01 16:33:02.008 Status: dzVents: Info: moonSelectorIcons v 1.02: ------ Start external script: moonSelectorIcons.lua: Device: "Lune (Virtuel Environnent)", Index: 63
2020-01-01 16:33:02.008 Status: dzVents: Debug: moonSelectorIcons v 1.02: lastLevel30
2020-01-01 16:33:02.008 Status: dzVents: Debug: moonSelectorIcons v 1.02: level20
2020-01-01 16:33:02.009 Status: dzVents: Debug: moonSelectorIcons v 1.02: OpenURL: url = http://127.0.0.1:8080/json.htm?type=setused&used=true&name=Lune&description=&idx=63&switchtype=18&customimage=111
2020-01-01 16:33:02.009 Status: dzVents: Debug: moonSelectorIcons v 1.02: OpenURL: method = GET
2020-01-01 16:33:02.009 Status: dzVents: Debug: moonSelectorIcons v 1.02: OpenURL: post data = nil
2020-01-01 16:33:02.009 Status: dzVents: Debug: moonSelectorIcons v 1.02: OpenURL: headers = nil
2020-01-01 16:33:02.009 Status: dzVents: Debug: moonSelectorIcons v 1.02: OpenURL: callback = nil
2020-01-01 16:33:02.009 Status: dzVents: Info: moonSelectorIcons v 1.02: ------ Finished moonSelectorIcons.lua
2020-01-01 16:33:02.010 Error: dzVents: local netWork not open for dzVents openURL call !
2020-01-01 16:33:02.010 Error: dzVents: check dzVents wiki (look for 'Using dzVents with Domoticz') 
Domoticz Bêta v4.11670
Xiaomi, Sonoff, Blitzwolf, Harmony, Broadlink, Amazon, Ikea, Yeelight, Roborock, Aqara, Nut, Zigate, RfLink, MySensors, ESPEasy, Etc

Site Web : https://mcflypartages.fr
Chaine YouTube : https://youtube.com/mcflypartages
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: DZVents : DarkSky et probabilité de pluie

Message par papoo »

Dans Domoticz, allez dans Configuration> Paramètres> Autre et dans la section EventSystem assurez-vous que la case à cocher 'dzVents désactivé' n'est pas cochée. Assurez-vous également que dans la section Sécurité des paramètres (Configuration> Paramètres> Système> Réseaux locaux (pas de nom d'utilisateur / mot de passe), vous autorisez 127.0.0.1 à ne pas avoir besoin d'un mot de passe. DzVents utilise ce port pour envoyer certaines commandes à Domoticz.
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
McFlyPartages
Messages : 28
Inscription : 28 nov. 2019, 20:50
Localisation : Finistere
Contact :

Resolu: DZVents : DarkSky et probabilité de pluie

Message par McFlyPartages »

papoo a écrit : 01 janv. 2020, 16:46
Dans Domoticz, allez dans Configuration> Paramètres> Autre et dans la section EventSystem assurez-vous que la case à cocher 'dzVents désactivé' n'est pas cochée. Assurez-vous également que dans la section Sécurité des paramètres (Configuration> Paramètres> Système> Réseaux locaux (pas de nom d'utilisateur / mot de passe), vous autorisez 127.0.0.1 à ne pas avoir besoin d'un mot de passe. DzVents utilise ce port pour envoyer certaines commandes à Domoticz.
Réseau local j'ai mis 127.0.0.*;192.168.10.*

DzVents est bien activé.

Via http://192.168.10.57:8080/json.htm?type ... mimage=117
l'image change mais si je change au sélecteur rien ne se passe ni quand le script darksky et rafraîchi


Edit Final : Problème résolue il fallait que je redémarre pour qu'il prenne en compte la modif de réseau .

Merci pour ton aide en tous cas merci aussi pour tes scripts.
Dernière modification par McFlyPartages le 01 janv. 2020, 17:02, modifié 1 fois.
Domoticz Bêta v4.11670
Xiaomi, Sonoff, Blitzwolf, Harmony, Broadlink, Amazon, Ikea, Yeelight, Roborock, Aqara, Nut, Zigate, RfLink, MySensors, ESPEasy, Etc

Site Web : https://mcflypartages.fr
Chaine YouTube : https://youtube.com/mcflypartages
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: DZVents : DarkSky et probabilité de pluie

Message par papoo »

ce n'est pas l'activation ou la désactivation de dzvents qu'il faut regarder, mais de
ssurez-vous également que dans la section Sécurité des paramètres (Configuration> Paramètres> Système> Réseaux locaux (pas de nom d'utilisateur / mot de passe), vous autorisez 127.0.0.1 à ne pas avoir besoin d'un mot de passe. DzVents utilise ce port pour envoyer certaines commandes à Domoticz.
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
McFlyPartages
Messages : 28
Inscription : 28 nov. 2019, 20:50
Localisation : Finistere
Contact :

Re: DZVents : DarkSky et probabilité de pluie

Message par McFlyPartages »

papoo a écrit : 01 janv. 2020, 17:00 ce n'est pas l'activation ou la désactivation de dzvents qu'il faut regarder, mais de
ssurez-vous également que dans la section Sécurité des paramètres (Configuration> Paramètres> Système> Réseaux locaux (pas de nom d'utilisateur / mot de passe), vous autorisez 127.0.0.1 à ne pas avoir besoin d'un mot de passe. DzVents utilise ce port pour envoyer certaines commandes à Domoticz.
Oui j'avais bien compris mais il faut redémarrer pour qu'il prenne en compte le changement.

Encore merci
Domoticz Bêta v4.11670
Xiaomi, Sonoff, Blitzwolf, Harmony, Broadlink, Amazon, Ikea, Yeelight, Roborock, Aqara, Nut, Zigate, RfLink, MySensors, ESPEasy, Etc

Site Web : https://mcflypartages.fr
Chaine YouTube : https://youtube.com/mcflypartages
joebuz
Messages : 29
Inscription : 13 mars 2019, 23:52

Re: DZVents : DarkSky et probabilité de pluie

Message par joebuz »

Bonjour,

J'avais installé ce script il y a un mois et tout fonctionnait correctement.
Hier j'ai voulu mettre à jour Domoticz pour la version 11804 mais cela à fait planter Domoticz, impossible à récupérer...
J'ai ré-installé une sauvegarde que j'avais faite avec l'ancienne version 4.10717 DzVents 2.4.19, tout mes appareils fonctionnent correctement sauf ce sript, voici les logs :

Code : Tout sélectionner

 2020-03-28 22:53:28.125 Error: EventSystem: in moonSelectorIcons: [string "--[[ moonSelectorIcons.lua..."]:16: attempt to index global 'domoticz' (a nil value)
2020-03-28 22:53:54.132 Error: EventSystem: in darksky: [string "--[[ darksky.lua for [ dzVents >= 2.4.14 (dom..."]:87: attempt to index global 'domoticz' (a nil value)
Les lignes indiquées correspondent à :

Code : Tout sélectionner

 logging =   {  level    =   domoticz.LOG_DEBUG,
1) Quelqu'un aurait-il une idée pour corriger ce problème ? je n'ai aucune valeur qui appraît dans mes capteurs météo %, ni pour les phases de la lune
2) J'ai vu que la nouvelle version implémentait les capteurs Darsky, quelqu'un a-t-il réussi à faire la maj et à utiliser ces capteurs natifs à la place des capteurs virtuels ?
RPI3 (Buster) + AEOTEC Z-Stick Gen5
Version: 2020.2 Build Hash: b63341bc0
Compile Date: 2020-04-26 13:47:55
dzVents Version: 3.0.2
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: DZVents : DarkSky et probabilité de pluie

Message par papoo »

pourrais tu poster ton script modifié stp?
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
joebuz
Messages : 29
Inscription : 13 mars 2019, 23:52

Re: DZVents : DarkSky et probabilité de pluie

Message par joebuz »

darksky.lua :

Code : Tout sélectionner

local scriptName        = 'Darksky forecast'
local scriptVersion     = ' 1.21'
local proba_pluie_h     = {}
local prev_wind_h       = {}
local MoonPhaseSelect   = {}

proba_pluie_h[1]        = 'Proba Pluie 1h'
proba_pluie_h[2]        = 'Proba Pluie 2h'
proba_pluie_h[3]        = nil
proba_pluie_h[4]        = 'Proba Pluie 4h'
proba_pluie_h[5]        = nil
proba_pluie_h[6]        = 'Proba Pluie 6h'
proba_pluie_h[12]       = 'Proba Pluie 12h'
proba_pluie_h[24]       = 'Proba Pluie 24h'
proba_pluie_h[36]       = nil
proba_pluie_h[48]       = nil

prev_wind_h[1]          = 'Meteo 1h'
prev_wind_h[2]          = 'Meteo 2h'
prev_wind_h[3]          = nil
prev_wind_h[4]          = 'Meteo 4h'
prev_wind_h[5]          = nil
prev_wind_h[6]          = 'Meteo 6h'
prev_wind_h[12]         = 'Meteo 12h'
prev_wind_h[24]         = 'Meteo 24h'
prev_wind_h[36]         = nil
prev_wind_h[48]         = nil

MoonPhaseSelect[1]      = 'Phase Lune'  --moonPhase day 1 selector switch
MoonPhaseSelect[2]      = nil   --moonPhase day 2 selector switch
MoonPhaseSelect[3]      = nil   --moonPhase day 3 selector switch
MoonPhaseSelect[4]      = nil   --moonPhase day 4 selector switch
MoonPhaseSelect[5]      = nil   --moonPhase day 5 selector switch
MoonPhaseSelect[6]      = nil   --moonPhase day 6 selector switch
MoonPhaseSelect[7]      = nil   --moonPhase day 7 selector switch
MoonPhaseSelect[8]      = nil   --moonPhase day 8 selector switch

return {
    active = true,
    on      =   {   timer           =   { 'every 15 minutes' },  -- remember only 1000 requests by day, 30mn = 48 requests, 5mn = 288 requests
                    httpResponses   =   { 'DarkSky_Trigger' }    -- Trigger the handle Json part
                },

  logging =   {  level    =   domoticz.LOG_DEBUG,                                           -- Seulement un niveau peut être actif; commenter les autres
                -- level    =   domoticz.LOG_INFO,                                            -- Only one level can be active; comment others
                -- level    =   domoticz.LOG_ERROR,
                -- level    =   domoticz.LOG_MODULE_EXEC_INFO,
                marker = scriptName..' v'..scriptVersion
                },

   data    =   {   Forecast     = {initial = {} },             -- Keep a copy of last json just in case
       },
    execute = function(domoticz, item)

        local function logWrite(str,level)             -- Support function for shorthand debug log statements
            domoticz.log(tostring(str),level or domoticz.LOG_DEBUG)
        end

        local function quadrants(degrees)
            local quadrants = {"NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"}
            
                if degrees > 348.75 or degrees <= 11.25 then
                    return "N"
                else 
                    local index = tonumber(math.floor((degrees - 11.25) / 22.5)+1)
                    return quadrants[index]
                end
        end
        local function levelMoonhase(moonphase)
            local level = 10 -- level correspondant à Nouvelle lune
            if(moonphase > 0.05 and moonphase < 0.245) then
                level = 20 -- level correspondant à Premier croissant
            elseif(moonphase > 0.244 and moonphase < 0.255) then 
                level = 30 -- level correspondant à Premier quartier
            elseif(moonphase > 0.255 and moonphase < 0.495) then
                level = 40  -- level correspondant à Gibbeuse croissante
            elseif(moonphase > 0.495 and moonphase < 0.55) then
                level = 50 -- level correspondant à Pleine lune
            elseif(moonphase > 0.55 and moonphase < 0.745) then
                level = 60 -- level correspondant à Gibbeuse décroissante
            elseif(moonphase > 0.745 and moonphase < 0.755) then
                level = 70 -- level correspondant à Dernier quartier
            elseif(moonphase > 0.755 and moonphase < 1.00) then
                level = 80 -- level correspondant à Dernier croissant
            end
            return level--moonPhase, 
        end
        --local DarkSkyAPIkey = domoticz.variables('api_forecast_io').value
        local DarkSkyAPIkey = "79befc923d072ad0f0520bdb13632551"
        --local geolocalisation = domoticz.settings.location.latitude..','..domoticz.settings.location.longitude
        local geolocalisation = "47.617433,-0.891835" -- latitude,longitude
        logWrite('geolocalisation : '..geolocalisation,domoticz.LOG_INFO)


        local Forecast_url  = "https://api.darksky.net/forecast/"  -- url
        local extraData = "?units=si&exclude=flags"--currently,minutely,daily,alerts,

        if (item.isTimer) then
            domoticz.openURL({
                url = Forecast_url..DarkSkyAPIkey.."/"..geolocalisation..extraData,
                callback = 'DarkSky_Trigger'
            })

        end
        if (item.isHTTPResponse and item.ok) then
            -- we know it is json but dzVents cannot detect this
            -- convert to Lua
            local json = domoticz.utils.fromJSON(item.data)
            -- json is now a Lua table
            if #item.data > 0 then
                domoticz.data.Forecast    = domoticz.utils.fromJSON(item.data)
                rt = domoticz.utils.fromJSON(item.data)
            else
                domoticz.log("Problem with response from DarkSky (no data) using data from earlier run",domoticz.LOG_ERROR)
                rt  = domoticz.data.Forecast                        -- json empty. Get last valid from domoticz.data
                if #rt < 1 then                                         -- No valid data in domoticz.data either
                    domoticz.log("No previous data. are DarkSkyAPIkey and geolocalisation ok?",domoticz.LOG_ERROR)
                    return false
                end
            end
            logWrite('heure systeme')
            local now = domoticz.time.dDate
            logWrite('now : '..now)
            j = 1
            for i = 1,48 do
                logWrite('j : '..j)
                if now > tonumber(json.hourly.data[j].time) then -- si maintenant est supérieur au timestamp lu
                    local h = domoticz.utils.round((now - tonumber(json.hourly.data[j].time)) / 3600,0)
                    logWrite("h : "..h)
                    j = j+h
                    logWrite("j : "..j)

                end
                logWrite('date :'.. os.date('%Y-%m-%d %H:%M:%S', json.hourly.data[j].time),domoticz.LOG_INFO)
                logWrite('precipProbability :' ..json.hourly.data[j].precipProbability,domoticz.LOG_INFO)
                if (proba_pluie_h[i]) then
                        domoticz.devices(proba_pluie_h[i]).updatePercentage(json.hourly.data[j].precipProbability*100)
                end

                local windSpeed         =   json.hourly.data[j].windSpeed
                local windGust          =   json.hourly.data[j].windGust
                local windBearing       =   json.hourly.data[j].windBearing
                local temperature       =   json.hourly.data[j].temperature
                local windChill         =   json.hourly.data[j].apparentTemperature
                local direction         =   quadrants(windBearing)
                logWrite('windSpeed : '..tostring(windSpeed)..' windGust : '..tostring(windGust)..' windBearing : '..tostring(windBearing)..' direction :'..tostring(direction)..' temperature : '..tostring(temperature)..' windChill : '..tostring(windChill),domoticz.LOG_INFO)

                if (prev_wind_h[i]) then
                    domoticz.devices(prev_wind_h[i]).updateWind(windBearing,tostring(direction),windSpeed,windGust,temperature,windChill)
                    logWrite('mise à jour du device '..prev_wind_h[i],domoticz.LOG_INFO)
                end
                
                if j == 48 then break end
                j = j +1
            end
            k = 1
            for k = 1,8 do
                local moonphase = json.daily.data[k].moonPhase
                logWrite('moonPhase day ' ..k..' : '..tostring(moonphase))
                logWrite(levelMoonhase(moonphase))

                if(MoonPhaseSelect[k]) then
                    domoticz.devices(MoonPhaseSelect[k]).switchSelector(levelMoonhase(moonphase))
                    logWrite("update selector device")
                end
                if j == 8 then break end
                j = j +1
            end
        end
    end
}
moonSelectorIcons.lua :

Code : Tout sélectionner

local scriptName        = 'moonSelectorIcons'
local scriptVersion     = ' 1.0'
return  {   
        active = true,
        on =    {  
                       devices         = {66}, -- change to your device(s) separated by a comma like {2479,2480} 
                    },

  logging =   {  level    =   domoticz.LOG_DEBUG,                                             -- Seulement un niveau peut être actif; commenter les autres
                -- level    =   domoticz.LOG_INFO,                                            -- Only one level can be active; comment others
                -- level    =   domoticz.LOG_ERROR,
                -- level    =   domoticz.LOG_MODULE_EXEC_INFO,
                marker = scriptName..' v'..scriptVersion
                },

    execute = function(domoticz, item)
    
        local function logWrite(str,level)
            domoticz.log(tostring(str),level or domoticz.LOG_DEBUG)
        end
        local icons =     { 
                            [10] = 101,-- level correspondant à Nouvelle lune
                            [20] = 102,-- level correspondant à Premier croissant
                            [30] = 103,-- level correspondant à Premier quartier
                            [40] = 104,-- level correspondant à Gibbeuse croissante
                            [50] = 105,-- level correspondant à Pleine lune
                            [60] = 106,-- level correspondant à Gibbeuse décroissante
                            [70] = 107,-- level correspondant à Dernier quartier
                            [80] = 108,-- level correspondant à Dernier croissant
                        }
        
        local function setIcon(iconNumber) 
            local url = domoticz.settings['Domoticz url'] .. '/json.htm?type=setused&used=true&name=' .. domoticz.utils.urlEncode(item.name) ..
            '&description=' .. domoticz.utils.urlEncode(item.description) .. -- Required. If not set it will be blanked out.
            '&idx=' .. item.id .. 
            '&switchtype=' .. item.switchTypeValue ..
            '&customimage=' .. iconNumber
            logWrite(url)
            return domoticz.openURL(url)
        end    
        logWrite('lastLevel'.. tostring(item.lastLevel))
        logWrite('level'.. tostring(item.level))
        if item.level ~= item.lastLevel then 
            setIcon(icons[item.level])
            domoticz.log('Changement icone Phase Lune : changé' .. item.id,domoticz.LOG_DEBUG)
        else
            domoticz.log('Changement icone Phase Lune : pas necessaire' .. item.id,domoticz.LOG_DEBUG)
        end
    end
}
pour les 2 scripts j'ai essayé de décommenter ces 3 niveau de logs un par un et un seul à la fois, j'ai toujours les mêmes messages d'erreur, seul le numéro de ligne change.
level = domoticz.LOG_DEBUG,
-- level = domoticz.LOG_INFO,
-- level = domoticz.LOG_ERROR,
RPI3 (Buster) + AEOTEC Z-Stick Gen5
Version: 2020.2 Build Hash: b63341bc0
Compile Date: 2020-04-26 13:47:55
dzVents Version: 3.0.2
Répondre