Pokaż wiadomości

Ta sekcja pozwala Ci zobaczyć wszystkie wiadomości wysłane przez tego użytkownika. Zwróć uwagę, że możesz widzieć tylko wiadomości wysłane w działach do których masz aktualnie dostęp.


Pokaż wątki - rafal_ll

Strony: [1]
1
Vera / Vera Plus
« dnia: Styczeń 07, 2017, 03:05:16 pm  »
Szukam alternatywy dla HC2 po ostatniej awarii w tej chwili nie mam siły na walkę z HC
Kiedyś miałem centralkę vera lite i tam był język PL nie wiem jak teraz i co się zmieniło na plus
Minęły trzy lata
Jak wygląda interfejs
Czy konfigurację można przenosić między centralkami np. kupię lite i przeniosę za jakiś czas do Plus
Może to są całkowicie inne systemy i się nie da?
Czy centralki można łączyć po LAN jak w Fibaro

Proszę o jakieś info

2
OpenHab, Domoticz, Jeedom itd... / Domoticz zmienna do Fibaro
« dnia: Listopad 11, 2016, 10:01:59 pm  »
Panowie jak przesłać z Domoticza np.temperaturę do zmiennej w fibaro
Fibarolink nie działa

---------------------------------------------------------------------------------------------------------------------------
Można ją pobrać przez pętlę główną urządzenia wirtualnego np tak

Domoticz = Net.FHttp("192.168.1.107",8084) --adres domoticza
response ,status, errorCode = Domoticz:GET("/json.htm?type=devices&rid=153") --153 nr urządzenia
jsonTable = json.decode(response)
local Data = jsonTable.result[1].Data
fibaro:setGlobal("Paliwo", Data) --zmienna do zaktualizowania
fibaro:sleep(60*1000) --czas zwłoki pętli

3
Fibaro - urządzenia wirtualne, pluginy / Radio DAB+ z wifi...Sterowanie?
« dnia: Luty 15, 2016, 07:33:36 pm  »
Znalazłem ciekawe radia DAB+ z rozgłośniami internetowym oparty na frontier-silicon na przykład takie
https://www.technisat.com/de_DE/DigitRadio-110-IR/352-10774-10574/

Zastanawiam się czy można tym sterować przez urządzenie wirtualne ?

4
Witam
      Udało mi się postawić stronę na Synology według pomysłu ze forum

http://www.domotique-fibaro.fr/index.php/topic/466-graph-de-temp%C3%A9rature-humidit%C3%A9-consommationsur-nas/

Wyszło to całkiem nieźle

Opanowałem jak wysyłać dane ze zmiennych

Nie wiem skąd pobiera dane meteo
I nie działa mi temperatura pomieszczeń, mimo że pobrał nazwy pomieszczeń
Proszę kolegów o pomoc sam sobie nie poradzę

Tu są kody z przycisków


Sensors

--------------------------------------------------
-- Button  : 1 => Sensors : Temperature, Humidity, Light, ...
-- Author  : Lazer
-- Version : 5.0
-- Date    : September 2015
--------------------------------------------------

-- User Global Variables
local variables = {
{
["type"] = "temperature",
["id"]   = 2001,
["name"] = "Temp_Webasto"
},



}

-- System variables
local debug = false
local selfID = fibaro:getSelfId()
local ip = fibaro:get(selfID, 'IPAddress')
local port = fibaro:get(selfID, 'TCPPort')
local NAS = Net.FHttp(ip, tonumber(port))
local erreur = 0
local sensors = {
{
["type"] = "temperature",
[3] = "temperature_sensor",
[4] = "com.fibaro.temperatureSensor"
},
{
["type"] = "humidity",
[3] = "humidity_sensor",
[4] = "com.fibaro.humiditySensor"
},
{
["type"] = "temperature",
[3] = "thermostat_setpoint",
[4] = "com.fibaro.setPoint"
},
{
["type"] = "temperature",
[3] = "thermostat_setpoint",
[4] = "com.fibaro.thermostatHorstmann"
},
{
["type"] = "light",
[3] = "light_sensor",
[4] = "com.fibaro.lightSensor"
}
}
local netatmo = {
["CO2"] = "co2",
["Press"] = "pressure",
["Noise"] = "noise",
["Rain"] = "rain"
}

-- Send data to NAS (SQL DB)
function SendDataNAS (datas)
if debug then
fibaro:debug(json.encode(datas))
end
if #datas > 0 then
local payload = "/graph/data_post.php"
local response, status, errorCode = NAS:POST(payload, json.encode(datas))
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable = json.decode(response);
if jsonTable.success ~= true then
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">Error '..(jsonTable.error and jsonTable.error.code or "???")..' : '..(jsonTable.error and jsonTable.error.message or "???")..'</span>')
elseif debug then
fibaro:debug('<span style="display:inline;color:green;">OK : '..(jsonTable.rowcount or "???")..' lines inserted in DB</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">Error : Can not connect to NAS, errorCode='..errorCode..', status='..status..', payload='..payload..', response='..(response or "")..'</span>')
end
end
end

-- Get HC2 software version
local HC2 = Net.FHttp("127.0.0.1", 11111)
payload = "/api/settings/info"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable = json.decode(response)
if tonumber(jsonTable.softVersion) >= 4 then
version = 4
else
version = 3
end
if debug then
fibaro:debug("v"..version)
end

-- Get HC2 Device list
for i = 1, #sensors do
payload = "/api/devices?type=" .. sensors[i][version]
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then

-- Get data
local datas = {}
jsonTable = json.decode(response)
for j = 1, #jsonTable do
-- Exclude hidden, disabled, and dead devices
if jsonTable[j].visible and jsonTable[j].visible == true and jsonTable[j].enabled and jsonTable[j].enabled == true and jsonTable[j].properties.dead and jsonTable[j].properties.dead == "false" then
datas[#datas+1] = {}
datas[#datas].id = jsonTable[j].id
datas[#datas].timestamp = 'NULL'
datas[#datas].type = sensors[i].type
datas[#datas].value = jsonTable[j].properties.value
elseif debug then
fibaro:debug("Device "..jsonTable[j].id.." "..jsonTable[j].name.." excluded")
end
end

-- Send data to NAS
SendDataNAS(datas)

else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end
end

-- Get HC2 Netatmo Plugin Device
if version == 4 then
payload = "/api/devices?type=com.fibaro.netatmoWeatherStation"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then

-- Get data
jsonTable = json.decode(response)
if jsonTable[1] and jsonTable[1].properties and jsonTable[1].properties.childTable and jsonTable[1].properties.childTable ~= "" then
local datas = {}
local childTable = json.decode(jsonTable[1].properties.childTable)
for id, data in pairs(childTable) do
local sensor = data:match("%.([^%.]+)") -- Split string after dot
for k,v in pairs(netatmo) do
if sensor == k then
-- Get sensor
local value = fibaro:getValue(id, "value")
if debug then
fibaro:debug(id..' '..fibaro:getName(id)..' : '..value)
end
datas[#datas+1] = {}
datas[#datas].id = id
datas[#datas].timestamp = 'NULL'
datas[#datas].type = v
datas[#datas].value = value
break
end
end
end

-- Send data to NAS
SendDataNAS(datas)

elseif debug then
fibaro:debug('<span style="display:inline;color:red;">No Netatmo device found')
end

else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end
elseif debug then
fibaro:debug('<span style="display:inline;color:red;">Netatmo plugin not supported')
end

else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end

-- Get Meteo
local datas = {}
datas[1] = {}
datas[1].id = 3
datas[1].timestamp = 'NULL'
datas[1].type = "temperature"
datas[1].value = fibaro:getValue(3, "Temperature")
datas[2] = {}
datas[2].id = 3
datas[2].timestamp = 'NULL'
datas[2].type = "humidity"
datas[2].value = fibaro:getValue(3, "Humidity")
datas[3] = {}
datas[3].id = 3
datas[3].timestamp = 'NULL'
datas[3].type = "wind"
datas[3].value = fibaro:getValue(3, "Wind")
-- Send data to NAS
SendDataNAS(datas)

-- Get User Variable list (updated from FHEM through API)
datas = nil
local datas = {}
for i = 1, #variables do
payload = "/graph/data_post_" .. variables[i].type .. ".php?id=" .. variables[i].id .. "&value=" .. fibaro:getGlobalValue(variables[i].name)
datas[#datas+1] = {}
datas[#datas].id = variables[i].id
datas[#datas].timestamp = 'NULL'
datas[#datas].type = variables[i].type
datas[#datas].value = fibaro:getGlobalValue(variables[i].name)
end
-- Send data to NAS
SendDataNAS(datas)

if erreur > 0 then
fibaro:log("Erreur")
else
fibaro:log("Sensors uploaded")
end



Power

--------------------------------------------------
-- Button  : 2 => Power
-- Author  : Lazer
-- Version : 5.0
-- Date    : September 2015
--------------------------------------------------

-- System variables
local debug = false
local selfID = fibaro:getSelfId()
local ip = fibaro:get(selfID, 'IPAddress')
local port = fibaro:get(selfID, 'TCPPort')
local NAS = Net.FHttp(ip, tonumber(port))
local erreur = 0

-- Send data to NAS (SQL DB)
function SendDataNAS (datas)
if debug then
fibaro:debug(json.encode(datas))
end
if #datas > 0 then
local payload = "/graph/data_post.php"
local response, status, errorCode = NAS:POST(payload, json.encode(datas))
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable = json.decode(response);
if jsonTable.success ~= true then
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">Error '..(jsonTable.error and jsonTable.error.code or "???")..' : '..(jsonTable.error and jsonTable.error.message or "???")..'</span>')
elseif debug then
fibaro:debug('<span style="display:inline;color:green;">OK : '..(jsonTable.rowcount or "???")..' lines inserted in DB</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">Error : Can not connect to NAS, errorCode='..errorCode..', status='..status..', payload='..payload..', response='..(response or "")..'</span>')
end
end
end

-- Get HC2 software version
local HC2 = Net.FHttp("127.0.0.1", 11111)
payload = "/api/settings/info"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable = json.decode(response)
if tonumber(jsonTable.softVersion) >= 4 then
version = 4
else
version = 3
end
if debug then
fibaro:debug("v"..version)
end
-- Get HC2 Device list
payload = "/api/devices"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then

-- Get data
local datas = {}
jsonTable = json.decode(response)
for i = 1, #jsonTable do
if version == 4 then
-- Exclude hidden, disabled, and dead devices
if jsonTable[i].interfaces and jsonTable[i].visible and jsonTable[i].visible == true and jsonTable[i].enabled and jsonTable[i].enabled == true and jsonTable[i].properties.dead and jsonTable[i].properties.dead == "false" then
-- Look for devices returning power consumption
for j = 1, #jsonTable[i].interfaces do
if jsonTable[i].interfaces[j] == "power" then
local power = jsonTable[i].properties.power
if debug then
fibaro:debug(jsonTable[i].id.." "..jsonTable[i].name.." "..power.."W")
end
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].timestamp = 'NULL'
datas[#datas].type = "power"
datas[#datas].value = power
break
end
end
end
elseif version == 3 then
-- Look for devices returning power consumption
if jsonTable[i].properties.unitSensor and jsonTable[i].properties.unitSensor == "W" then
power = jsonTable[i].properties.valueSensor
if debug then
fibaro:debug(jsonTable[i].id.." "..jsonTable[i].name.." "..power.."W")
end
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].timestamp = 'NULL'
datas[#datas].type = "power"
datas[#datas].value = power
end
end
end

-- Send data to NAS
SendDataNAS(datas)

else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end

if erreur > 0 then
fibaro:log("Erreur")
else
fibaro:log("Power uploaded")
end


Battery
--------------------------------------------------
-- Button  : 3 => Battery
-- Author  : Lazer
-- Version : 5.0
-- Date    : September 2015
--------------------------------------------------

-- System variables
local debug = true
local selfID = fibaro:getSelfId()
local ip = fibaro:get(selfID, 'IPAddress')
local port = fibaro:get(selfID, 'TCPPort')
local NAS = Net.FHttp(ip, tonumber(port))
local erreur = 0

-- Get HC2 software version
local HC2 = Net.FHttp("127.0.0.1", 11111)
payload = "/api/settings/info"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable = json.decode(response)
if tonumber(jsonTable.softVersion) >= 4 then
version = 4
else
version = 3
end
if debug then
fibaro:debug("v"..version)
end
-- Get HC2 Device list
payload = "/api/devices"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
local batteries = {}
jsonTable = json.decode(response)
for i = 1, #jsonTable do
if version == 4 then
-- Keep only parent devices
-- Notes : Z-Wave devices have parentId=1
--         Plugins (like Netatmo or Krikroff's Virtual Sensor) have parentId=0
if jsonTable[i].parentId and jsonTable[i].parentId == 1 then
-- Look for battery operated devices
if jsonTable[i].interfaces then
for j = 1, #jsonTable[i].interfaces do
if jsonTable[i].interfaces[j] == "battery" then
local batteryLevel = jsonTable[i].properties.batteryLevel
if tonumber(batteryLevel) == 255 then batteryLevel = 0 end
if tonumber(batteryLevel) > 100 then batteryLevel = 100 end
if debug then
fibaro:debug(jsonTable[i].id.." "..jsonTable[i].name.." "..batteryLevel.."%")
end
-- Prepare JSON data
batteries[#batteries+1] = {}
batteries[#batteries].id = jsonTable[i].id
batteries[#batteries].date = os.date("%Y-%m-%d")
batteries[#batteries].type = "battery"
batteries[#batteries].value = batteryLevel
break
end
end
end
end
elseif version == 3 then
-- Keep only parent devices
if jsonTable[i].properties.parentID and jsonTable[i].properties.parentID == "1" then
-- Look for battery operated devices
if jsonTable[i].properties.isBatteryOperated and jsonTable[i].properties.isBatteryOperated == "1" then
local batteryLevel = jsonTable[i].properties.batteryLevel
if tonumber(batteryLevel) == 255 then batteryLevel = "0" end
if tonumber(batteryLevel) > 100 then batteryLevel = "100" end
if debug then
fibaro:debug(jsonTable[i].id.." "..jsonTable[i].name.." "..batteryLevel.."%")
end
-- Prepare JSON data
batteries[#batteries+1] = {}
batteries[#batteries].id = jsonTable[i].id
batteries[#batteries].date = os.date("%Y-%m-%d")
batteries[#batteries].type = "battery"
batteries[#batteries].value = batteryLevel
end
end
end
end

-- Send data to NAS (SQL DB)
if debug then
fibaro:debug(json.encode(batteries))
end
payload = "/graph/data_post.php"
response, status, errorCode = NAS:POST(payload, json.encode(batteries))
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable2 = json.decode(response);
if jsonTable2.success == true then
fibaro:debug('<span style="display:inline;color:green;">OK : '..(jsonTable2.rowcount or "???")..' lines inserted in DB</span>')
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">Error '..(jsonTable2.error and jsonTable2.error.code or "???")..' : '..(jsonTable2.error and jsonTable2.error.message or "???")..'</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">Error : Can not connect to NAS, errorCode='..errorCode..', status='..status..', payload='..payload..', response='..(response or "")..'</span>')
end

else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end

if erreur > 0 then
fibaro:log("Erreur")
else
fibaro:log("Batteries uploaded")
end



Devices


--------------------------------------------------
-- Button  : 4 => Devices
-- Author  : Lazer
-- Version : 5.0
-- Date    : September 2015
--------------------------------------------------

-- User Global Variables
local variables = {
  {
["type"] = "temperature",
["id"]   = 2001,
["name"] = "Webasto",
["room"] = 8 -- Garaż
},
}

-- System variables
local debug = true
local selfID = fibaro:getSelfId()
local ip = fibaro:get(selfID, 'IPAddress')
local port = fibaro:get(selfID, 'TCPPort')
local NAS = Net.FHttp(ip, tonumber(port))
local erreur = 0
local datas = {}
local sensors = {
{
["type"] = "temperature",
[3] = "temperature_sensor",
[4] = "com.fibaro.temperatureSensor"
},
{
["type"] = "humidity",
[3] = "humidity_sensor",
[4] = "com.fibaro.humiditySensor"
},
{
["type"] = "temperature",
[3] = "thermostat_setpoint",
[4] = "com.fibaro.setPoint"
},
{
["type"] = "temperature",
[3] = "thermostat_setpoint",
[4] = "com.fibaro.thermostatHorstmann"
},
{
["type"] = "light",
[3] = "light_sensor",
[4] = "com.fibaro.lightSensor"
}
}
local netatmo = {
["CO2"] = "co2",
["Press"] = "pressure",
["Noise"] = "noise",
["Rain"] = "rain"
}

-- Get HC2 software version
local HC2 = Net.FHttp("127.0.0.1", 11111)
payload = "/api/settings/info"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable = json.decode(response)
if tonumber(jsonTable.softVersion) >= 4 then
version = 4
else
version = 3
end
if debug then
fibaro:debug("v"..version)
end

-- Get HC2 Device list
payload = "/api/devices"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
-- Get data
jsonTable = json.decode(response)
for i = 1, #jsonTable do
if version == 4 then
if jsonTable[i].interfaces then
for j = 1, #jsonTable[i].interfaces do
-- Look for devices returning power consumption
if jsonTable[i].interfaces[j] == "power" then
local deviceName = jsonTable[i].name
local roomID = jsonTable[i].roomID
local roomName = fibaro:getRoomNameByDeviceID(jsonTable[i].id)
if debug then
fibaro:debug(i.." "..jsonTable[i].id.." "..jsonTable[i].name.." "..roomName)
end
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].type = 'power'
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].type = 'energy'
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
end
-- Look for battery operated devices
if jsonTable[i].interfaces[j] == "battery" then
-- Keep only parent devices
if jsonTable[i].parentId and jsonTable[i].parentId == 1 then
local deviceName = jsonTable[i].name
local roomID = jsonTable[i].roomID
local roomName = fibaro:getRoomNameByDeviceID(jsonTable[i].id)
if debug then
fibaro:debug(i.." "..jsonTable[i].id.." "..jsonTable[i].name.." "..roomName)
end
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].type = 'battery'
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
end
end
end
end
-- Look for sensors devices returning environmental values
for j = 1, #sensors do
if jsonTable[i].type == sensors[j][version] then
local deviceName = jsonTable[i].name
local roomID = jsonTable[i].roomID
local roomName = fibaro:getRoomNameByDeviceID(jsonTable[i].id)
if debug then
fibaro:debug(i.." "..jsonTable[i].id.." "..deviceName.." "..roomName)
end
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].type = sensors[j].type
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
end
end
elseif version == 3 then
-- Look for devices returning power consumption
if jsonTable[i].properties.unitSensor and jsonTable[i].properties.unitSensor == "W" then
local deviceName = jsonTable[i].name
local roomID = jsonTable[i].roomID
local roomName = fibaro:getRoomNameByDeviceID(jsonTable[i].id)
if debug then
fibaro:debug(i.." "..jsonTable[i].id.." "..jsonTable[i].name.." "..roomName)
end
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].type = 'power'
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].type = 'energy'
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
end
-- Look for battery operated devices
if jsonTable[i].properties.isBatteryOperated and jsonTable[i].properties.isBatteryOperated == "1" then
-- Keep only parent devices
if jsonTable[i].properties.parentID and jsonTable[i].properties.parentID == "1" then
local deviceName = jsonTable[i].name
local roomID = jsonTable[i].roomID
local roomName = fibaro:getRoomNameByDeviceID(jsonTable[i].id)
if debug then
fibaro:debug(i.." "..jsonTable[i].id.." "..jsonTable[i].name.." "..roomName)
end
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].type = 'battery'
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
end
end
-- Look for sensors devices returning environmental values
for j = 1, #sensors do
if jsonTable[i].type == sensors[j][version] then
local deviceName = jsonTable[i].name
local roomID = jsonTable[i].roomID
local roomName = fibaro:getRoomNameByDeviceID(jsonTable[i].id)
if debug then
fibaro:debug(i.." "..jsonTable[i].id.." "..jsonTable[i].name.." "..roomName)
end
datas[#datas+1] = {}
datas[#datas].id = jsonTable[i].id
datas[#datas].type = sensors[j].type
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
end
end
end
end
else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end

-- Get HC2 Netatmo Weather Station plugin device
if version == 4 then
payload = "/api/devices?type=com.fibaro.netatmoWeatherStation"
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
-- Get data
jsonTable = json.decode(response)
if jsonTable[1] and jsonTable[1].properties and jsonTable[1].properties.childTable and jsonTable[1].properties.childTable ~= "" then
local childTable = json.decode(jsonTable[1].properties.childTable)
for id, data in pairs(childTable) do
local sensor = data:match("%.([^%.]+)") -- Split string after dot
for k,v in pairs(netatmo) do
if sensor == k then
local deviceName = fibaro:getName(id)
local roomID = fibaro:getRoomID(id)
local roomName = fibaro:getRoomNameByDeviceID(id)
if debug then
fibaro:debug(id.." "..deviceName.." "..roomName)
end
datas[#datas+1] = {}
datas[#datas].id = id
datas[#datas].type = v
datas[#datas].name = deviceName
datas[#datas].roomid = roomID
datas[#datas].roomname = roomName
break
end
end
end
elseif debug then
fibaro:debug('<span style="display:inline;color:red;">No Netatmo device found')
end
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end
elseif debug then
fibaro:debug('<span style="display:inline;color:red;">Netatmo plugin not supported')
end

else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">status='..status..', errorCode='..errorCode..', payload='..payload..', response='..(response or "")..'</span>')
end

-- Get Weather devices
--local deviceName = fibaro:getName(3)
local deviceName = 'Météo'
if debug then
fibaro:debug("1 3 "..deviceName)
end
datas[#datas+1] = {}
datas[#datas].id = 3
datas[#datas].type = 'temperature'
datas[#datas].name = deviceName
datas[#datas].roomid = 0
datas[#datas].roomname = ''
if debug then
fibaro:debug("2 3 "..deviceName)
end
datas[#datas+1] = {}
datas[#datas].id = 3
datas[#datas].type = 'humidity'
datas[#datas].name = deviceName
datas[#datas].roomid = 0
datas[#datas].roomname = ''
if debug then
fibaro:debug("3 3 "..deviceName)
end
datas[#datas+1] = {}
datas[#datas].id = 3
datas[#datas].type = 'wind'
datas[#datas].name = deviceName
datas[#datas].roomid = 0
datas[#datas].roomname = ''

-- Get User Variable list (From FHEM)
for i = 1, #variables do
local roomName = fibaro:getRoomName(variables[i].room)
if debug then
fibaro:debug(i.." "..variables[i].id.." "..variables[i].name.." "..roomName)
end
datas[#datas+1] = {}
datas[#datas].id = variables[i].id
datas[#datas].type = variables[i].type
datas[#datas].name = variables[i].name
datas[#datas].roomid = variables[i].room
datas[#datas].roomname = roomName
end

-- Send data to NAS (SQL DB)
if debug then
fibaro:debug(json.encode(datas))
end
payload = "/graph/device_post.php"
response, status, errorCode = NAS:POST(payload, json.encode(datas))
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable2 = json.decode(response)
if jsonTable2.success == true then
fibaro:debug('<span style="display:inline;color:green;">OK : '..(jsonTable2.rowcount or "???")..' lines inserted in DB</span>')
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">Error '..(jsonTable2.error and jsonTable2.error.code or "???")..' : '..(jsonTable2.error and jsonTable2.error.message or "???")..'</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="display:inline;color:red;">Error : Can not connect to NAS, errorCode='..errorCode..', status='..status..', payload='..payload..', response='..(response or "")..'</span>')
end

if erreur > 0 then
fibaro:log("Erreur")
else
fibaro:log("Devices uploaded")
end


Trend
local selfID = fibaro:getSelfId()
local ip = fibaro:get(selfID, 'IPAddress')
local port = fibaro:get(selfID, 'TCPPort')
local NAS = Net.FHttp(ip, tonumber(port))
local payload = "/graph/generate_trend.php"
response, status, errorCode = NAS:GET(payload)

if tonumber(errorCode) == 0 and tonumber(status) == 200 then
fibaro:log('Trends generated')
else
fibaro:debug('<span style="display:inline;color:red;">Error : Can not connect to NAS, errorCode='..errorCode..', status='..status..', payload='..payload..', response='..(response or "")..'</span>')
end




Energy
--------------------------------------------------
-- Button  : 6 => Energy (HC2)
-- Author  : Lazer
-- Version : 5.0
-- Date    : September 2015
--------------------------------------------------

-- System variables
local debug = false
local selfID = fibaro:getSelfId()
local ip = fibaro:get(selfID, 'IPAddress')
local port = fibaro:get(selfID, 'TCPPort')
local NAS = Net.FHttp(ip, tonumber(port))
local erreur = 0
local devices = {}

-- Get HC2 Device list
local HC2 = Net.FHttp("127.0.0.1", 11111)
response, status, errorCode = HC2:GET("/api/devices")
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable = json.decode(response)
for i, device in pairs(jsonTable) do
if device.visible and device.visible == true and device.enabled and device.enabled == true and device.properties.dead and device.properties.dead == "false" then
if device.properties.showEnergy then
if debug then
fibaro:debug("device => "..device.id.." "..device.name.." "..device.properties.power.."W")
end
table.insert(devices, device.id)
end
end
end
else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">Error : Can not connect to HC2, errorCode='..errorCode..', status='..status..', response='..(response or "")..'</span>')
end
local device = table.concat(devices, ',')
if debug then
fibaro:debug(device)
end

-- Get teleinfo data from NAS (SQL DB)
local payload = "/graph/teleinfo_energy_get.php"
response, status, errorCode = NAS:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
if debug then
fibaro:debug(response)
end
jsonTable = json.decode(response)
if jsonTable.success and jsonTable.success == true then
if jsonTable.data then
for jour, data in pairs(jsonTable.data) do -- using pairs() the order that items are returned is not defined, not even for indexed tables
fibaro:debug(jour)
-- On construit un tableau contenant le timestamp de début et de fin pour chaque plage horaire de tarification
local timestamps = {}
local j = 0
for i = 1, #data do
if debug then
fibaro:debug("data => "..i..' - '..data[i][1]..' : '..data[i][2])
end
timestamps[i] = {}
timestamps[i][0] = data[i][2] -- tarif
timestamps[i][1] = data[i][1] -- timestamp start
if i > 1 then
timestamps[i-1][2] = data[i][1] -- timestamp end
end
j = i
end
timestamps[j][2] = os.time({year=os.date("%Y", timestamps[1][1]), month=os.date("%m", timestamps[1][1]), day=os.date("%d", timestamps[1][1])+1, hour=os.date("%H", timestamps[1][1]), min=os.date("%M", timestamps[1][1]), sec=os.date("%S", timestamps[1][1])}) -- timestamp end of day

-- Get energy consumption for every devices in HC2
local energy = {}
for i = 1, #timestamps do
if debug then
fibaro:debug("timestamps => i = "..i.." - "..timestamps[i][0].." - "..timestamps[i][1].." "..timestamps[i][2])
end
payload = '/api/energy/'..timestamps[i][1]..'/'..timestamps[i][2]..'/compare/devices/power/'..device;
--fibaro:debug(payload)
response, status, errorCode = HC2:GET(payload)
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
--fibaro:debug(response)
jsonTable2 = json.decode(response)
--table.sort(jsonTable2, function(a,b) return a.id<b.id end) -- Sort results by id, because HC2 API seems to sort results by consumption
for j = 1, #jsonTable2 do
if not energy[jsonTable2[j].id] then
energy[jsonTable2[j].id] = {}
end
if debug then
fibaro:debug(jsonTable2[j].id.." "..jsonTable2[j].kWh)
end
energy[jsonTable2[j].id][timestamps[i][0]] = (energy[jsonTable2[j].id][timestamps[i][0]] or 0) + jsonTable2[j].kWh
end
else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">Error : Can not connect to HC2, errorCode='..errorCode..', status='..status..', payload='..payload..', response='..(response or "")..'</span>')
end
end

-- Prepare JSON data
local energies = {}
for id, toto in pairs(energy) do
energies[#energies+1] = {}
energies[#energies].id = id
energies[#energies].date = jour
energies[#energies].type = "energy"
for tarif, kwh in pairs(toto) do
if debug then
fibaro:debug("energy => id = "..id.." - tarif = "..tarif.." - kwh = "..kwh)
end
energies[#energies]["value_"..tarif] = kwh
end
end
table.sort(energies, function(a,b) return a.id<b.id end) -- Sort results by id
if debug then
fibaro:debug(json.encode(energies))
end

-- Send energy data to NAS (SQL DB)
payload = "/graph/data_post.php"
response, status, errorCode = NAS:POST(payload, json.encode(energies))
if tonumber(errorCode) == 0 and tonumber(status) == 200 and response ~= nil and response ~= "" then
jsonTable2 = json.decode(response);
if jsonTable2.success == true then
fibaro:debug('<span style="color:green;">OK : '..(jsonTable2.rowcount or "???")..' lines inserted in DB</span>')
else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">Error '..(jsonTable2.error and jsonTable2.error.code or "???")..' : '..(jsonTable2.error and jsonTable2.error.message or "???")..'</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">Error : Can not connect to NAS, errorCode='..errorCode..', status='..status..', payload='..payload..', response='..(response or "")..'</span>')
end

end
else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">Error : Missing data from NAS : '..payload..'</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">Error '..(jsonTable.error and jsonTable.error.code or "???")..' : '..(jsonTable.error and jsonTable.error.message or "???")..'</span>')
end
else
erreur = erreur + 1
fibaro:debug('<span style="color:red;">Error : Can not connect to NAS, errorCode='..errorCode..', status='..status..', payload='..payload..', response='..(response or "")..'</span>')
end

if erreur > 0 then
fibaro:log("Erreur")
else
fibaro:log("Consumption uploaded")
end


5
Fibaro - urządzenia wirtualne, pluginy / Pilot TV Samsung
« dnia: Kwiecień 05, 2015, 07:23:00 pm  »
Pilot Samsung… Takiego używam, powinien działać z większością modeli
W każdym przycisku należy zmienić IP telewizora

Strony: [1]