Page 1 sur 2

domoticz 2023.2 API LUA

Publié : 23 juil. 2023, 18:44
par marsflow
Hello les gens,

j'ai un domoticz qui gère un logement et l'un des scripts ne fonctionne plus,
je vous mets mon scripts

Code : Tout sélectionner

-- Fonction traite la réception des plaques immatriculation et ouvre le/les portails
--local debug = true
local Plaquecam1 = "Plaque"
local Portail406 = "portail total"
local inter_acces = "controle acces portail"
domoticzIP = '127.0.0.1'	--'127.0.0.1'
domoticzPORT = '9982'
domoticzUSER = 'xxxxn'		-- nom d'utilisateur
domoticzPSWD = 'xxxxxn'		-- mot de pass
domoticzPASSCODE = ''	-- pour interrupteur protégés
domoticzURL = 'http://'..domoticzIP..':'..domoticzPORT

IDX = 3042  --récupéération info plaque texte

local Florian, Plaque1 = uservariables['FlorianClio']:match("([^;]+);([^;]+)")

 
commandArray = {}

if (devicechanged["Plaque"]) and otherdevices[inter_acces]=='On' then

if (package.config:sub(1,1) == '/') then
	-- system linux
	luaDir = debug.getinfo(1).source:match("@?(.*/)")
	curl = '/usr/bin/curl -m 15 '		 							-- ne pas oublier l'espace à la fin
else
	-- system windows
	luaDir = string.gsub(debug.getinfo(1).source:match("@?(.*\\)"),'\\','\\\\')
	-- download curl : https://bintray.com/vszakats/generic/download_file?file_path=curl-7.54.0-win32-mingw.7z
	curl = 'c:\\Programs\\Curl\\curl.exe '		 					-- ne pas oublier l'espace à la fin
end
-- décrypte les information json/domoticz rid 
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Linux

--ancienne API JSON
 --local config=assert(io.popen(curl..'-u '..domoticzUSER..':'..domoticzPSWD..' "'..domoticzURL..'/json.htm?type=devices&rid='..IDX..'" &')) 
-- nouveau API JSON
local config=assert(io.popen(curl..'-u '..domoticzUSER..':'..domoticzPSWD..' "'..domoticzURL..'/json.htm?type=command&param=getdevices&rid='..IDX..'" &'))

local blocjson = config:read('*all ')
 config:close()
 -- print (blocjson)
 local jsonValeur = json:decode(blocjson)
         data=(jsonValeur.result[1].Data)
		   name=(jsonValeur.result[1].Name)
--fin


print ('####################')
print ('####################')
print ('passer plaque ' .. name .. ' N° ' .. data)
print ('####################')
print ('####################')
if (data == Plaque1) then  
--commandArray[portail406]='On' 
print ('ouverture portail 406 pour ' .. Florian .. ' plaque n°' .. Plaque1 .. '') 
--commandArray['SendNotification']='ouverure portail Pour Clio#ouverure portail Pour Clio#0#sound#extradata#subsystem'




end

end



return commandArray


alors mon soucis et qu'il décrypte sans les lignes result

celui du blocjson

Code : Tout sélectionner

2023-07-23 16:17:24.197 Status: LUA: {
2023-07-23 16:17:24.197 "ActTime" : 1690121844,
2023-07-23 16:17:24.197 "AstrTwilightEnd" : "23:50",
2023-07-23 16:17:24.197 "AstrTwilightStart" : "04:32",
2023-07-23 16:17:24.197 "CivTwilightEnd" : "22:14",
2023-07-23 16:17:24.197 "CivTwilightStart" : "06:08",
2023-07-23 16:17:24.197 "DayLength" : "14:58",
2023-07-23 16:17:24.197 "NautTwilightEnd" : "22:58",
2023-07-23 16:17:24.197 "NautTwilightStart" : "05:24",
2023-07-23 16:17:24.197 "ServerTime" : "2023-07-23 16:17:24",
2023-07-23 16:17:24.197 "SunAtSouth" : "14:11",
2023-07-23 16:17:24.197 "Sunrise" : "06:42",
2023-07-23 16:17:24.197 "Sunset" : "21:40",
2023-07-23 16:17:24.197 "app_version" : "2023.2",
2023-07-23 16:17:24.197 "status" : "OK",
2023-07-23 16:17:24.197 "title" : "Devices"
2023-07-23 16:17:24.197 }
celui du navigateur et ancienne version domoticz

Code : Tout sélectionner

{
	"ActTime" : 1690126900,
	"AstrTwilightEnd" : "23:50",
	"AstrTwilightStart" : "04:32",
	"CivTwilightEnd" : "22:14",
	"CivTwilightStart" : "06:08",
	"DayLength" : "14:58",
	"NautTwilightEnd" : "22:58",
	"NautTwilightStart" : "05:24",
	"ServerTime" : "2023-07-23 17:41:40",
	"SunAtSouth" : "14:11",
	"Sunrise" : "06:42",
	"Sunset" : "21:40",
	"app_version" : "2022.2",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CustomImage" : 0,
			"Data" : "Hello World",
			"Description" : "",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 22,
			"HardwareName" : "dummy",
			"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
			"HardwareTypeVal" : 15,
			"HaveTimeout" : false,
			"ID" : "00084260",
			"LastUpdate" : "2022-09-08 17:00:56",
			"Name" : "INFO Domo",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : false,
			"SignalLevel" : "-",
			"SubType" : "Text",
			"Timers" : "false",
			"Type" : "General",
			"TypeImg" : "text",
			"Unit" : 1,
			"Used" : 1,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "2260"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}

Re: domoticz 2023.2 API LUA

Publié : 23 juil. 2023, 20:52
par Neutrino
viewtopic.php?p=114494#p114494
Changement au niveau de l'API.

Re: domoticz 2023.2 API LUA

Publié : 24 juil. 2023, 14:49
par marsflow
Merci Neutrino,
J'ai vu oui qu'il y avait du changement,

J'ai déjà appliqué ceci :

--ancienne API JSON
--local config=assert(io.popen(curl..'-u '..domoticzUSER..':'..domoticzPSWD..' "'..domoticzURL..'/json.htm?type=devices&rid='..IDX..'" &'))



-- nouveau API JSON
local config=assert(io.popen(curl..'-u '..domoticzUSER..':'..domoticzPSWD..' "'..domoticzURL..'/json.htm?type=command&param=getdevices&rid='..IDX..'" &'))

Dans un navigateur il marque bien le result mais dans dans le blocjson j'ai pas la partie result.

Je suis revenu dans une version antérieures de domoticz pour le moment.



Envoyé de mon SM-S908B en utilisant Tapatalk


Re: domoticz 2023.2 API LUA

Publié : 24 juil. 2023, 18:16
par Keros
Le navigateur que tu utilises est sur le système qui exécute le code ? Il y a peut-être un souci de droits qui bloque les infos.

Tu partais de quelle version avant mise à jour ? Il y a eu pas mal de changement de sécurité avec 2023.1.

Re: domoticz 2023.2 API LUA

Publié : 24 juil. 2023, 18:28
par marsflow
J'ai fait avec chrome sur mon pc portable,
Et directement sur le raspbian dans le navigateur Chrome, les 2 j'avais result,
Je suis revenu à la Version: 2022.2

Envoyé de mon SM-S908B en utilisant Tapatalk

Re: domoticz 2023.2 API LUA

Publié : 24 juil. 2023, 19:19
par Keros
Regarde que tu es bien toujours le 127.0.0.1 dans les réseaux de confiance.

Re: domoticz 2023.2 API LUA

Publié : 24 juil. 2023, 19:26
par marsflow
J'ai regardé c'est bien le cas.

Envoyé de mon SM-S908B en utilisant Tapatalk

Re: domoticz 2023.2 API LUA

Publié : 09 août 2023, 15:50
par Zboun
Regarde si tu as ton dispositif dans l'admin.

"Configuration" > "Users" > Sur la ligne admin "Paramétrer les Dispositifs".

Re: domoticz 2023.2 API LUA

Publié : 09 août 2023, 23:12
par marsflow
Je regarderai, je vais retenter demain si j'ai le temps :D

Re: domoticz 2023.2 API LUA

Publié : 15 août 2023, 07:09
par denis_brasseur
J'ai eu les mêmes difficultés lors du passage en 2023.2.
J'ai du modifier ma ligne de commande en supprimant domoticzUSER.et domoticzPSWD, ce qui donne

Code : Tout sélectionner

local rid = assert(io.popen(curl..'"'..domoticzURL..'/json.htm?type=command&param=getdevices&rid='..idx]..'"'))