Page 1 sur 1

Recuperer CounterToday

Publié : 24 janv. 2020, 10:05
par jeannot
Bonjour,
Je veux récupérer la valeur de la Variable "CounterToday" d'un dispositif virtuel type compteur incrémental dans un script lua je vois uniquement counter. Merci pour votre aide

Code : Tout sélectionner

{
	"ActTime" : 1579855493,
	"AstrTwilightEnd" : "19:42",
	"AstrTwilightStart" : "06:50",
	"CivTwilightEnd" : "18:32",
	"CivTwilightStart" : "08:00",
	"DayLength" : "09:29",
	"NautTwilightEnd" : "19:08",
	"NautTwilightStart" : "07:24",
	"ServerTime" : "2020-01-24 09:44:53",
	"SunAtSouth" : "13:16",
	"Sunrise" : "08:32",
	"Sunset" : "18:01",
	"app_version" : "4.11641",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"Counter" : "4197 mm",
			"CounterToday" : "9 mm",
			"CustomImage" : 0,
			"Data" : "4197 mm",
			"Description" : "",
			"Favorite" : 0,
			"HardwareID" : 17,
			"HardwareName" : "VIRTUEL",
			"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
			"HardwareTypeVal" : 15,
			"HaveTimeout" : false,
			"ID" : "82103",
			"LastUpdate" : "2020-01-24 09:35:21",
			"Name" : "Pluie",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"SubType" : "Counter Incremental",
			"SwitchTypeVal" : 3,
			"Timers" : "false",
			"Type" : "General",
			"TypeImg" : "counter",
			"Unit" : 1,
			"Used" : 1,
			"ValueQuantity" : "Pluie",
			"ValueUnits" : "mm",
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "103"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}

Re: Recuperer CounterToday

Publié : 25 janv. 2020, 21:51
par Keros
Regarde avec la "fonction" Json.

Exemple :

Code : Tout sélectionner

    json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() 
    local config = assert(io.popen('/usr/bin/curl "http://IP_domoticZ:Port_domoticZ/json.htm?type=devices&rid=ID_device"'))
	local blocjson = config:read('*all')
	config:close()
	local jsonValeur = json:decode(blocjson)
	counterToday = jsonValeur.result[1].CounterToday

Re: Recuperer CounterToday

Publié : 25 janv. 2020, 22:25
par jeannot
Merci pour ton aide , j'avais commencé en bash :

Code : Tout sélectionner

result=$(curl -s "http://IP_domoticZ:8080/json.htm?type=devices&rid=103"| jq -r .result[].CounterToday)
le script fonctionne il me reste à transférer vers une variable utilisateur.

Re: Recuperer CounterToday

Publié : 26 janv. 2020, 10:39
par boum
À titre indicatif, un script équivalent en dzVents s'écrirait ainsi :

Code : Tout sélectionner

return {
	on = {
		devices = { 103 }
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
		local valeur = device.counterToday
		local variable = domoticz.variables('NomVariableAChanger')
		variable.set(valeur);
	end
}
(Avec possibilité de changer le 103 par le nom du dispositif)

Re: Recuperer CounterToday

Publié : 26 janv. 2020, 12:19
par jeannot
Super en dzVents et ça fonctionne .
Merci encore pour votre aide.