Asystent AI
Domoticz - pobieran...
 
Powiadomienia
Wyczyść wszystko

Domoticz Domoticz - pobieranie danych przez JSON

11 Wpisów
3 Użytkownicy
1 Reactions
4,015 Wyświetleń
(@prychol)
Wpisów: 18
Praktykant
Autor tematu
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 
[#2294]

Witam:)

Mam czujnik czystości powietrza z którego chciałbym mieć też odczyty w Domoticzu.

Z czujnika odczytuję dane po wpisaniu http://IP_CZUNIKA/data.json i otrzymuję dane w takim formacie:

{"software_version": "NAMF-2020-35", "age":"109", "measurements":"12620", "sensordatavalues":[{"value_type":"SDS_P1","value":"16.15"},{"value_type":"SDS_P2","value":"6.85"},{"value_type":"BME280_temperature","value":"0.61"},{"value_type":"BME280_humidity","value":"77.41"},{"value_type":"BME280_pressure","value":"100426.16"},{"value_type":"HECA_temperature","value":"3.47"},{"value_type":"HECA_humidity","value":"75.41"},{"value_type":"samples","value":"125682"},{"value_type":"min_micro","value":"1105"},{"value_type":"max_micro","value":"114772"},{"value_type":"signal","value":"-81"}]}

W jaki sposób można odczytać te dane w Domoticzu i przypisać pod jakiś konkretny wskaźnik? 


 
Dodane : 17/03/2021 11:13 pm
isom
 isom
(@isom)
Wpisów: 5319
Szef wszystkich szefów Moderator Zasłużony dla Forum, Donator 2K19, Donator 2K20
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

@prychol z tego Air Monitor możesz pobierać dane za pomocą żądań http metoda GET . Najbardziej optymalny do tego jest skrypt dzVents . Przykład ze strony wiki

return  { 
    on  =  { 
        timer  =  {  'every 5 minutes'  }, 
        httpResponses  =  {  'energyRetrieved'  } 
    }, 
    execute  =  function ( domoticz ,  item ) 
        if  ( item . isTimer )  then 
            domoticz . openURL ({ 
            url  =  'http: // url / to / service' , 
            method  =  'GET' , 
            callback  =  'energyRetrieved' 
            }) 
        elseif  (pozycja . isHTTPResponse )  to 
            if  ( item . ok )  then  - statusCode == 2xx 
                local  current  =  item . json . konsumpcja 
                domoticz . urządzenia ( „myCurrentUsage” ). updateEnergy ( current ) 
            end 
        end 
    end 
}

Zmieniając dane na np temperatura zamiast current , wstawiając odpowiedni interwał czasowy i poprawny URL masz pobieranie temp do wirtualnego czujnika w domoticz

 


 
Dodane : 18/03/2021 9:47 am
(@prychol)
Wpisów: 18
Praktykant
Autor tematu
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

Dziękuję za odpowiedź:)

Trochę mnie oświeciłeś, bo mam przecież w podobny sposób zrobione odczyty danych o COVID19 ze strony:

https://coronavirus-19-api.herokuapp.com/countries/Poland

Jak znajdę trochę czasu i uda mi się to zrobić to dam znać, a jak mi się nie uda to będę dopytywał dalej:)


 
Dodane : 18/03/2021 10:13 pm
(@kosiarz78)
Wpisów: 10
Bywalec
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

@prychol hej czy udalo ci sie cos w tym temacie zrobic?


 
Dodane : 23/01/2022 4:15 pm
(@prychol)
Wpisów: 18
Praktykant
Autor tematu
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

@kosiarz78 cześć, niestety nie działałem już z tym z powodu braku czasu


 
Dodane : 23/01/2022 6:11 pm
(@kosiarz78)
Wpisów: 10
Bywalec
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

Po wielu godzinach udało mi sie to ogarnąć 🙂 działa i to najważniejsze tylko chyba "Nam" i cały projekt upadł już..


 
Dodane : 12/03/2023 12:06 pm
(@prychol)
Wpisów: 18
Praktykant
Autor tematu
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

@kosiarz78 super, a podpowiedziałbyś jak to zrobić? może w jakiejś wolnej chwili dodałbym w końcu te odczyty do Domoticza 😉


 
Dodane : 13/03/2023 7:17 pm
(@kosiarz78)
Wpisów: 10
Bywalec
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

DzVents w domoticz. trzeba utworzyć wirtualne czujniki o nazwach z kodu i dodać kod do domoticz:

local FQDN = 'ip.czujnika'

return {
	active = true,
	on = {
		timer = { 'every minute' },
		httpResponses = { 'luftdatenRetrieved' } -- matches callback string below
	},
	execute = function(domoticz, item)

		if (item.isTimer) then
			domoticz.openURL({
				url = 'http://' .. FQDN .. '/data.json',
				method = 'GET',
				callback = 'luftdatenRetrieved'
			})
			
		elseif (item.isHTTPResponse) then
			if (item.ok and item.isJSON) then -- statusCode == 2xx
			    if tonumber(item.json.age) < 60 then
		    	    for i, t2 in pairs(item.json.sensordatavalues) do
                        if (t2.value_type == 'SDS_P1') then
                            domoticz.devices('Luftdaten PM10').updateCustomSensor(t2.value)
                        elseif (t2.value_type == 'SDS_P2') then
                            domoticz.devices('Luftdaten PM2.5').updateCustomSensor(t2.value)
                        elseif (t2.value_type == 'HECA_temperature') then
                            temperature = t2.value
                        elseif (t2.value_type == 'HECA_humidity') then
                            humidity = t2.value
                        elseif (t2.value_type == 'BME280_temperature') then
                            BME280_temperature = t2.value
                        elseif (t2.value_type == 'BME280_pressure') then
                            BME280_pressure = t2.value/100
                        elseif (t2.value_type == 'BME280_humidity') then
                            BME280_humidity = t2.value
                        end
                    end
--	    			if (SDS_P1 ~= nil) then
--		    	    	domoticz.devices('Luftdaten PM10').updateCustomSensor(SDS_P1)
--			        end
--			        if (SDS_P2 ~= nil) then
--                      domoticz.devices('Luftdaten PM2.5').updateCustomSensor(SDS_P2)
--                  end
                    if (HECA_temperature ~= nil and HECA_humidity ~= nil) then
                        domoticz.devices('Luftdaten DHT22').updateTempHum(temperature,humidity,0)
                    end
                    if (BME280_temperature ~= nil and BME280_humidity ~= nil and BME280_pressure ~= nil) then
--                      if (tonumber (BME280_temperature) < 100) and (tonumber (BME280_pressure) < 1050) then
                            domoticz.devices('Luftdaten BME280').updateTempHumBaro(BME280_temperature,BME280_humidity,0,BME280_pressure,0)
--                      end
                    end
				end
			else
				-- oops
				domoticz.log('Error fetching Luftdaten data', domoticz.LOG_ERROR)
				domoticz.log(item.data, domoticz.LOG_ERROR)
			end
		end
	end
}

 


 
Dodane : 14/03/2023 12:55 am
prychol zareagował
(@prychol)
Wpisów: 18
Praktykant
Autor tematu
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

@kosiarz78 dziękuję Ci bardzo:)
a działają Ci wszystkie pomiary, bo u mnie odczytuje tylko BME 280, a brak mam odczytów z HECA oraz PM2.5 i PM10?


 
Dodane : 14/03/2023 7:11 pm
(@kosiarz78)
Wpisów: 10
Bywalec
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

sprawdź czy json widać : http://192.168.x.x/data.json?

jak widać to ok

trzeba dostosować nazwy czujników z kodu do jsnon

nazwy: Luftdaten PM2.5, Luftdaten PM10 (oba Custom Sensor)


 
Dodane : 15/03/2023 9:13 pm
(@prychol)
Wpisów: 18
Praktykant
Autor tematu
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

@kosiarz78 a widzisz, ten typ sensora źle wybrałem, już jest ok:) Wielkie dzięki jeszcze raz:D


 
Dodane : 15/03/2023 10:30 pm
Udostępnij: