Asystent AI
Skrypt dzVents i pr...
 
Powiadomienia
Wyczyść wszystko

Skrypt dzVents i problem

2 Wpisów
2 Użytkownicy
0 Reactions
3,913 Wyświetleń
 skom
(@skom)
Wpisów: 40
Kontrybutor
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
 
[#1488]

Dzień dobry wszystkim forumowiczom. Zaczynam swoją zabawę z Inteligentnym Domem. Chcę podłączyć inwerter Afore do domoticza. Od dystrybutora tego inwertera dowiedziałem się, ze nie wystawia on json. Napisałem więc swój pierwszy skrypt w dzVents (lua), który pobiera dane bezpośrednia z http, i wybiera z tego pliku odpowiednie dane. Tylko zauważyłem, że skrypt "przechodzi dwa razy" - (skrypt i logi poniżej). Może ktoś z szanownych użytkowników jest "oblatany" w tej dziedzinie i nakieruje mnie jak mogę "poprawić" tę dolegliwość.

return {
  on = {
     timer = { 'every minute and between 30 minutes before sunrise and 30 minutes after sunset', 'at 00:01' },
    httpResponses = { 'data' }
  },

execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
  url = 'http://user:pass@10.1.9.9/status.html',
method = 'GET',
  callback = 'data'
})
end

if (item.isHTTPResponse and item.ok) then
domoticz.log('\n================ Odczytalem url ================', domoticz.log_debug)
-- wyciaganie danych z pobranych danych http
l1 = string.find ( item.data , 'var webdata_now_p = ' )
  l2 = string.find ( item.data , 'var webdata_today_e = ' )
l3 = string.find ( item.data , 'var webdata_total_e = ' )
  l4 = string.find ( item.data , 'var webdata_alarm = ' )
  s1 = string.sub ( item.data , l1+21, l2-5)
s2 = string.sub ( item.data , l2+23, l3-5)
  s3 = string.sub ( item.data , l3+23, l4-5)
  domoticz.devices('Solary - Now').updateCustomSensor(s1)
  domoticz.devices('Solary - Today').updateCustomSensor(s2)
  domoticz.devices('Solary - Total').updateCustomSensor(s3)
else
domoticz.log('\nBrak komunikacji z inverterem', domoticz.log_debug)
  if (domoticz.time.matchesRule('at 00:01')) then
 -- zerowanie dziennego po północy
   domoticz.log('\n================ Wstawiam: Today O ================', domoticz.log_debug)
domoticz.devices('Solary - Today').updateCustomSensor(0)
else
-- jak wyłaczony inwerter to bieżące 0 W
  domoticz.log('\n================ Wstawiam: Now O ================', domoticz.log_debug)
domoticz.devices('Solary - Now').updateCustomSensor(0)
end
end
end
}

LOGI:
2020-02-01 09:19:00.345 Status: dzVents: Info: ------ Start internal script: http_status:, trigger: every minute and between 30 minutes before sunrise and 30 minutes after sunset
2020-02-01 09:19:00.346 Status: dzVents: Info:
2020-02-01 09:19:00.346 ================ Brak komunikacji z inverterem ================
2020-02-01 09:19:00.346 Status: dzVents: Info:
2020-02-01 09:19:00.346 ================ Wstawiam: Now 0 ================
2020-02-01 09:19:00.416 Status: dzVents: Info: ------ Finished http_status
2020-02-01 09:19:00.428 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-02-01 09:19:00.449 Status: EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_kodi.lua
2020-02-01 09:19:01.104 Status: dzVents: Info: Handling httpResponse-events for: "data
2020-02-01 09:19:01.104 Status: dzVents: Info: ------ Start internal script: http_status: HTTPResponse: "data"
2020-02-01 09:19:01.104 Status: dzVents: Info:
2020-02-01 09:19:01.104 ================ Odczytalem url ================
2020-02-01 09:19:01.152 Status: dzVents: Info: ------ Finished http_status


 
Dodane : 01/02/2020 12:54 pm
(@wikor)
Wpisów: 2
Świeżak
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
 

Witam,

Trochę poprawiłem skrypt i u mnie działa zadowalająco.

Urządzenia: AforeToday - Electricity (instant and couter), AforeTotal - Custom Sensor

 

return {
on = {
timer = { 'every minute between 60 minutes before sunrise and 60 minutes after sunset'},
httpResponses = { 'data' }
},

execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://admin:passwd@192.168.1.2/status.html',
method = 'GET',
callback = 'data'
})
elseif(item.isHTTPResponse) then
if (item.ok) then
domoticz.log('\n================ Odczytuję dane inwertera ================')
-- wyciaganie danych z pobranych danych http
l1 = string.find ( item.data , 'var webdata_now_p = ' )
l2 = string.find ( item.data , 'var webdata_today_e = ' )
l3 = string.find ( item.data , 'var webdata_total_e = ' )
l4 = string.find ( item.data , 'var webdata_alarm = ' )
s1 = string.sub ( item.data , l1+21, l2-5)
s2 = string.sub ( item.data , l2+23, l3-5)
s2kwh = s2*1000
s3 = string.sub ( item.data , l3+23, l4-5)
print('Moc chwilowa============= ' .. s1 .. ' W')
print('Produkcja dzisiejsza===== ' .. s2 .. ' kWh')
print('Produkcja całkowita====== ' .. s3 .. ' kWh')
domoticz.devices('AforeToday').updateElectricity(s1,s2kwh)
domoticz.devices('AforeTotal').updateCustomSensor(s3)
else 
domoticz.log('\n=== Inwerter jeszcze/już nie pracuje lub problem z połączniem ====')
end 
end
end
}

 
Dodane : 11/02/2020 5:14 pm
Udostępnij: