Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par papoo »

escuse j'ai edité mon post avant que tu ne réponde
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par papoo »

et je ne mettrais pas
history.add(devices)
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
Anthony72
Messages : 13
Inscription : 05 mai 2018, 15:22

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par Anthony72 »

J'ai une erreur sur : local history = domoticz.data['Luminosité extérieure']
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par papoo »

essaie avec des parenthèses plutôt que des crochets
local history = domoticz.data('Luminosité extérieure')
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
Anthony72
Messages : 13
Inscription : 05 mai 2018, 15:22

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par Anthony72 »

Ça marche pas non plus :(
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par papoo »

tu as modifié

Code : Tout sélectionner

        data = {
            Lum_table = { history = true, maxMinutes = 15 }
        }
par

Code : Tout sélectionner

        data = {
            ['Luminosité extérieure'] = { history = true, maxMinutes = 15 }
        }
?
avec ensuite

Code : Tout sélectionner

local history = domoticz.data['Luminosité extérieure']
pas simple sans pouvoir tester :(
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
Anthony72
Messages : 13
Inscription : 05 mai 2018, 15:22

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par Anthony72 »

Oui, le début ressemble à ça pour le moment :

Code : Tout sélectionner

return {
	on = {
		active = true,
		timer = {'every minute'},
		devices = {
			'Volets roulants - Mode Manu/Auto',
            'Volets roulants - Commande générale',
--			'Volet roulant - Cuisine',
--			'Volet roulant - Ch. 1',
			'Volet roulant - Ch. 2',
			'Volet roulant - Ch. 3',
			'Volet roulant - SDE',
			'Volet roulant - WC',
            'Capteur 0-10V - Entrée n°1',
            'Luminosité extérieure',
		},
        data = {
            ['Luminosité extérieure'] = { history = true, maxMinutes = 15 },
            Lum_table = { history = true, maxMinutes = 15 },
        }
	},

	execute = function(domoticz, switch, timer)
        	    
        ------------------------------
        --  Mise à jour luminosité  --
        ------------------------------
        
        -- Mise à jour du capteur :
        Lum_ext=domoticz.devices('Capteur 0-10V - Entrée n°1').level
		domoticz.devices('Luminosité extérieure').updateLux(Lum_ext*600)
		
		-- Calcul de la moyenne :
        local switch = domoticz.devices('Luminosité extérieure')
        local history = domoticz.data('Luminosité extérieure')
--        history.add('Luminosité extérieure')
        Lum_moy = 10 --history.avg()
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par papoo »

pardon il te faut bien la ligne
history.add
mais il faut préciser ce que tu souhaites historiser
exemple
history.add(device.WhActual)

mais le script sur lequel je m'appuie pour t'aider n'est pas un script_time mais un script_device (dans le fonctionnement)
et dans les logs à chaque execution du script j'ai
dzVents: Info: Handling events for: "mon device", value: "0.000;385900.000"
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
Anthony72
Messages : 13
Inscription : 05 mai 2018, 15:22

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par Anthony72 »

Faut surement que je mette : history.add(device.lux) ?
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Automatisation volet roulant - Problème sur calcul d'une valeur moyenne

Message par papoo »

reprenons avec un script simple qui fonctionne chez moi
fais le fonctionner avec une sonde de temperature afin de valider son fonctionnement
ensuite adapte le à ton device LUX

Code : Tout sélectionner

    return {
        active = true,
        on = {
            devices = {'Temperature exterieure'}
        },
        data = {
            temperatures = { history = true, maxItems = 10 }
        },
        execute = function(domoticz, device)
            -- add new data
            domoticz.data.temperatures.add(device.temperature)

            -- average
            local average = domoticz.data.temperatures.avg()
            domoticz.log("moyenne = " .. average)

        end
2018-05-08 15:24:36.660 dzVents: Info: Handling events for: "Temperature exterieure", value: "24.4;48;1"
2018-05-08 15:24:36.660 dzVents: Info: ------ Start external script: history_temp.lua: Device: "Temperature exterieure (RFXCOM)", Index: 711
2018-05-08 15:24:36.663 dzVents: Info: moyenne = 24.333332697551
2018-05-08 15:24:36.665 dzVents: Info: ------ Finished history_temp.lua
2018-05-08 15:25:09.025 User: Admin initiated a switch command (150/Damocles/On)
2018-05-08 15:25:29.666 dzVents: Info: Handling events for: "Temperature exterieure", value: "24.4;47;1"
2018-05-08 15:25:29.666 dzVents: Info: ------ Start external script: history_temp.lua: Device: "Temperature exterieure (RFXCOM)", Index: 711
2018-05-08 15:25:29.670 dzVents: Info: moyenne = 24.349999427796
2018-05-08 15:25:29.672 dzVents: Info: ------ Finished history_temp.lua
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
Répondre