Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub4Eddy authored Jan 21, 2021
1 parent 5099312 commit d3dac3b
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions Iungo_Monitor-05.fqa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"Iungo Monitor","type":"com.fibaro.energyMeter","apiVersion":"1.2","initialProperties":{"viewLayout":{"$jason":{"body":{"header":{"style":{"height":"0"},"title":"quickApp_device_606"},"sections":{"items":[{"components":[{"name":"label1","style":{"weight":"1.2"},"text":"Label","type":"label"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"name":"button1","style":{"weight":"1.2"},"text":"Update Devicelist","type":"button"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"}]}},"head":{"title":"quickApp_device_606"}}},"uiCallbacks":[{"callback":"button1Event","eventType":"onReleased","name":"button1"}],"quickAppVariables":[{"name":"IPaddress","value":"192.168.178.12"},{"name":"Path","value":"/iungo/api_request"},{"name":"Method","value":"{\"seq\":1,\"method\":\"object_list_props_values\",\"arguments\":{\"oid\":\"538d72d9\"}}"},{"name":"powerID","value":"0"},{"name":"Interval","value":"10"},{"name":"debugLevel","value":"1"}],"typeTemplateInitialized":true},"files":[{"name":"main","isMain":true,"isOpen":true,"content":"-- IUNGO MONITOR \n\n-- This Quickapp retrieves power consumption, power production and gas usage from the (Iungo Monitor) energy and gas meter \n-- All power consumption of all HomeCenter devices is summerized\n-- The difference between the total power consumption and the power consumption of the HomeCenter devices is put in a unused device (unless the powerID = 0 or empty)\n-- In the QuickApp labels power consumption, power production and gas usage is shown \n-- The net consumption is also shown in de log (under the icon)\n\n\n-- Version 0.5 (21th January 2021)\n-- Initial version\n\n\n-- Variables (mandatory and automaticaly generated): \n-- IPaddress = IP address of your Iungo Monitor\n-- Path = Path, normally \"/iungo/api_request\" (don't changes unless you know what you are doing)\n-- Method = Method, normally '{\"seq\":1,\"method\":\"object_list_props_values\",\"arguments\":{\"oid\":\"538d72d9\"}}' (don't changes unless you know what you are doing)\n-- Interval = Number in seconds, the Lungo Monitor normally is updated every 10 seconds\n-- powerID = ID of the device where you want to capture the 'delta' power, use 0 if you don't want to store the energy consumption\n-- debugLevel = Number (1=some, 2=few, 3=all, 4=simulation mode) (default = 1)\n\n-- Example content Json table\n-- {\"ok\":true,\"type\":\"response\",\"time\":0.0026875899638981,\"rv\":{\"propsval\":[{\"id\":\"name\",\"value\":\"EnergieDirect\"},{\"id\":\"metertype\",\"value\":\"XMX\"},{\"id\":\"version\",\"value\":\"5\"},{\"id\":\"serial_e\",\"value\":\"4999999999999999999999999999999996\"},{\"id\":\"usage\",\"value\":516},{\"id\":\"T1\",\"value\":10817.833},{\"id\":\"T2\",\"value\":5398.875},{\"id\":\"-T1\",\"value\":4379.797},{\"id\":\"-T2\",\"value\":9959.182},{\"id\":\"L1I\",\"value\":1},{\"id\":\"L2I\",\"value\":1},{\"id\":\"L3I\",\"value\":2},{\"id\":\"L1Pimp\",\"value\":0.054},{\"id\":\"L2Pimp\",\"value\":0.125},{\"id\":\"L3Pimp\",\"value\":0.336},{\"id\":\"L1Pexp\",\"value\":0},{\"id\":\"L2Pexp\",\"value\":0},{\"id\":\"L3Pexp\",\"value\":0},{\"id\":\"c_tariff\",\"value\":2},{\"id\":\"serial_g\",\"value\":\"4999999999999999999999999999999995\"},{\"id\":\"gas_usage\",\"value\":0},{\"id\":\"gas\",\"value\":3903.388},{\"id\":\"Cost-T1\",\"value\":0.20721},{\"id\":\"Cost-T2\",\"value\":0.22921},{\"id\":\"Cost-nT1\",\"value\":0.20721},{\"id\":\"Cost-nT2\",\"value\":0.22921},{\"id\":\"Cost-gas\",\"value\":0.7711},{\"id\":\"Gas-interval\",\"value\":3600},{\"id\":\"Client-blob\",\"value\":\"\"},{\"id\":\"available\",\"value\":true}]},\"systime\":1610986159,\"seq\":1,\"error\":false}\n\n\n-- No editing of this code is needed \n\n\nfunction QuickApp:logging(level,text) -- Logging function for debug\n if tonumber(debugLevel) >= tonumber(level) then \n self:debug(text)\n end\nend\n\n\nfunction QuickApp:button1Event() -- Refresh button event\n self:updateView(\"button1\", \"text\", \"Please wait...\")\n self:onInit()\n fibaro.setTimeout(3000, function()\n self:updateView(\"button1\", \"text\", \"Update Devicelist\")\n end)\nend\n\n\nfunction QuickApp:updateProperties() -- Update the properties\n self:updateProperty(\"value\",tonumber(string.format(\"%.0f\",net_consumption)))\n self:updateProperty(\"unit\", \"Watt\")\n self:updateProperty(\"log\", tarifcodeText)\nend\n\n\nfunction QuickApp:updateLabels() -- Update the labels \n local labelText = \"Net consumption: \" ..net_consumption ..\" Watt \" ..tarifcodeText ..\"\\n\\n\"\n labelText = labelText ..\"Consumption: \" ..consumption ..\" Watt\" ..\"\\n\" \n labelText = labelText ..\"Production: \" ..production ..\" Watt\" ..\"\\n\"\n labelText = labelText ..\"Net consumption: \" ..net_consumption ..\" Watt \" ..\"\\n\\n\"\n labelText = labelText ..\"Gross consumption: \" ..gross_consumption ..\" Watt\" ..\"\\n\"\n labelText = labelText ..\"Device consumption: \" ..device_consumption ..\" Watt\" ..\"\\n\\n\"\n labelText = labelText ..\"Total consumption high: \" ..consumption_high ..\" kWh\" ..\"\\n\" \n labelText = labelText ..\"Total consumption low: \" ..consumption_low ..\" kWh\" ..\"\\n\"\n labelText = labelText ..\"Total consumption: \" ..total_consumption ..\" kWh\" ..\"\\n\" \n labelText = labelText ..\"Total production high: \" ..production_high ..\" kWh\" ..\"\\n\" \n labelText = labelText ..\"Total producton low: \" ..production_low ..\" kWh\" ..\"\\n\"\n labelText = labelText ..\"Total production: \" ..total_production ..\" kWh\" ..\"\\n\"\n labelText = labelText ..\"Total gas: \" ..gas ..\" M3\"\n\n self:updateView(\"label1\", \"text\", labelText)\n self:logging(2,labelText)\nend\n\n\nfunction QuickApp:updateConsumption() -- Update the energy consumption of all energy devices\n local deviceValue = 0\n local id = 1\n device_consumption = 0\n gross_consumption = 0\n for key, id in pairs(eDevices) do\n if fibaro.getValue(id, \"power\") and id~=powerID then\n deviceValue = fibaro.getValue(id, \"power\")\n self:logging(5,fibaro.getName(id) ..\" (ID \" ..id ..\"): \" ..deviceValue ..\" Watt\")\n device_consumption = device_consumption + deviceValue\n end\n end\n gross_consumption = tonumber(net_consumption) - device_consumption -- Measured power usage minus power usage from all devices\n if powerID == 0 or powerID == nil then\n --self:warning(\"No powerID to store net power consumption\")\n else\n api.put(\"/devices/\"..powerID, {[\"properties\"]={[\"power\"]=gross_consumption}}) -- Put gross_consumption into device with powerID\n end\nend\n\n\nfunction QuickApp:getValues() -- Get the values from json file\n consumption = string.format(\"%.1f\",jsonTable.rv.propsval[5].value)\n consumption_low = string.format(\"%.3f\",jsonTable.rv.propsval[6].value)\n consumption_high = string.format(\"%.3f\",jsonTable.rv.propsval[7].value)\n --production = string.format(\"%.1f\",jsonTable.PRODUCTION_W)\n production = \"0\" -- Temp setting\n production_low = string.format(\"%.3f\",jsonTable.rv.propsval[8].value)\n production_high = string.format(\"%.3f\",jsonTable.rv.propsval[9].value)\n consumption_gas = string.format(\"%.3f\",jsonTable.rv.propsval[21].value)\n gas = string.format(\"%.3f\",jsonTable.rv.propsval[22].value)\n net_consumption = string.format(\"%.1f\",jsonTable.rv.propsval[5].value - production) -- Temp setting use of production\n total_consumption = string.format(\"%.3f\",(jsonTable.rv.propsval[6].value + jsonTable.rv.propsval[7].value))\n total_production = string.format(\"%.3f\",(jsonTable.rv.propsval[8].value + jsonTable.rv.propsval[9].value))\n tarifcode = jsonTable.rv.propsval[19].value\n\n if tarifcode == \"2\" then\n tarifcodeText = \"(High)\"\n elseif tarifcode == \"1\" then\n tarifcodeText = \"(Low)\"\n else\n tarifcodeText = \"\"\n end\nend\n\n\nfunction QuickApp:getData() -- Get data from Iungo Monitor\n local url = \"http://\" ..IPaddress ..Path\n \n self.http:request(url, {\n options = {\n data = Method,\n method = \"POST\",\n headers = {\n [\"Content-Type\"] = \"application/json\",\n [\"Accept\"] = \"application/json\",\n }\n },\n success = function(response) \n self:logging(3,\"Response status: \" ..response.status)\n self:logging(3,\"Response data: \" ..response.data)\n\n local apiResult = response.data\n self:logging(4,\"apiResult\" ..apiResult)\n \n jsonTable = json.decode(apiResult) -- Decode the json string from api to lua-table\n\n self:getValues() -- Get the values from json file\n self:updateConsumption() -- Store net consumption in unused device\n self:updateLabels() -- Update the labels\n self:updateProperties() -- Update the properties\n\n end,\n error = function(message)\n self:logging(3,\"error: \" ..message)\n self:updateProperty(\"log\", \"error: \" ..json.encode(error))\n end\n })\n\n fibaro.setTimeout(Interval*1000, function() -- Checks every [Interval] seconds for new data\n self:getData()\n end)\nend \n\n\nfunction QuickApp:simData() -- Simulate Iungo Monitor\n apiResult = '{\"ok\":true,\"type\":\"response\",\"time\":0.0026875899638981,\"rv\":{\"propsval\":[{\"id\":\"name\",\"value\":\"EnergieDirect\"},{\"id\":\"metertype\",\"value\":\"XMX\"},{\"id\":\"version\",\"value\":\"5\"},{\"id\":\"serial_e\",\"value\":\"4999999999999999999999999999999996\"},{\"id\":\"usage\",\"value\":516},{\"id\":\"T1\",\"value\":10817.833},{\"id\":\"T2\",\"value\":5398.875},{\"id\":\"-T1\",\"value\":4379.797},{\"id\":\"-T2\",\"value\":9959.182},{\"id\":\"L1I\",\"value\":1},{\"id\":\"L2I\",\"value\":1},{\"id\":\"L3I\",\"value\":2},{\"id\":\"L1Pimp\",\"value\":0.054},{\"id\":\"L2Pimp\",\"value\":0.125},{\"id\":\"L3Pimp\",\"value\":0.336},{\"id\":\"L1Pexp\",\"value\":0},{\"id\":\"L2Pexp\",\"value\":0},{\"id\":\"L3Pexp\",\"value\":0},{\"id\":\"c_tariff\",\"value\":2},{\"id\":\"serial_g\",\"value\":\"4999999999999999999999999999999995\"},{\"id\":\"gas_usage\",\"value\":0},{\"id\":\"gas\",\"value\":3903.388},{\"id\":\"Cost-T1\",\"value\":0.20721},{\"id\":\"Cost-T2\",\"value\":0.22921},{\"id\":\"Cost-nT1\",\"value\":0.20721},{\"id\":\"Cost-nT2\",\"value\":0.22921},{\"id\":\"Cost-gas\",\"value\":0.7711},{\"id\":\"Gas-interval\",\"value\":3600},{\"id\":\"Client-blob\",\"value\":\"\"},{\"id\":\"available\",\"value\":true}]},\"systime\":1610986159,\"seq\":1,\"error\":false}'\n self:logging(4,\"apiResult\" ..apiResult)\n\n jsonTable = json.decode(apiResult) -- Decode the json string from api to lua-table\n\n self:getValues() -- Get the values from json file\n self:updateConsumption() -- Store net consumption in unused device\n self:updateLabels() -- Update the labels\n self:updateProperties() -- Update the properties\n\n fibaro.setTimeout(Interval*1000, function() -- Checks every [Interval] seconds for new data\n self:simData()\n end)\nend \n\n\nfunction QuickApp:geteDevices() -- Get all Device IDs which measure Energy Consumption\n eDevices = {}\n local devices, status = api.get(\"/devices?interface=energy\")\n self:trace(\"Updated devicelist devices with energy consumption\")\n for k in pairs(devices) do\n table.insert(eDevices,devices[k].id)\n end\n self:logging(2,\"Energy Devices: \" ..json.encode(eDevices))\nend\n\n\nfunction QuickApp:getGlobals() -- Get all Global Variables or create them\n IPaddress = self:getVariable(\"IPaddress\")\n Path = self:getVariable(\"Path\")\n Method = self:getVariable(\"Method\")\n powerID = tonumber(self:getVariable(\"powerID\"))\n Interval = tonumber(self:getVariable(\"Interval\")) \n debugLevel = tonumber(self:getVariable(\"debugLevel\"))\n\n -- Check existence of the mandatory variables, if not, create them with default values \n if IPaddress == \"\" or IPaddress == nil then \n IPaddress = \"192.168.178.12\" -- Default IPaddress \n self:setVariable(\"IPaddress\", IPaddress)\n self:trace(\"Added QuickApp variable IPaddress\")\n end\n if Path == \"\" or Path == nil then \n Path = \"/iungo/api_request\" -- Default Path\n self:setVariable(\"Path\", Path)\n self:trace(\"Added QuickApp variable Path\")\n end \n if Method == \"\" or Method == nil then \n Method = '{\"seq\":1,\"method\":\"object_list_props_values\",\"arguments\":{\"oid\":\"538d72d9\"}}' -- Default Method\n self:setVariable(\"Method\", Method)\n self:trace(\"Added QuickApp variable Method\")\n end\n if powerID == \"\" or powerID == nil then \n powerID = \"0\" -- ID of the device where you want to capture the 'delta' power, use 0 if you don't want to store the energy consumption\n self:setVariable(\"powerID\", powerID)\n self:trace(\"Added QuickApp variable powerID\")\n powerID = tonumber(powerID)\n end\n if Interval == \"\" or Interval == nil then\n Interval = \"10\" -- Default interval in seconds (The Iungo meter normally reads every 10 seconds)\n self:setVariable(\"Interval\", Interval)\n self:trace(\"Added QuickApp variable Interval\")\n Interval = tonumber(Interval)\n end\n if debugLevel == \"\" or debugLevel == nil then\n debugLevel = \"1\" -- Default value for debugLevel\n self:setVariable(\"debugLevel\",debugLevel)\n self:trace(\"Added QuickApp variable debugLevel\")\n debugLevel = tonumber(debugLevel)\n end\n if powerID == 0 or powerID == nil then\n self:warning(\"No powerID to store net power consumption\")\n end\nend\n\n\nfunction QuickApp:onInit()\n __TAG = fibaro.getName(plugin.mainDeviceId) ..\" ID:\" ..plugin.mainDeviceId\n self:debug(\"onInit\")\n\n self:getGlobals() -- Get Global Variables\n self:geteDevices() -- Get all Energy Devices\n\n self.http = net.HTTPClient({timeout=3000})\n \n if tonumber(debugLevel) >= 4 then \n self:simData() -- Go in simulation\n else\n self:getData() -- Get data from Iungo Monitor\n end\nend\n\n-- EOF "}]}

0 comments on commit d3dac3b

Please sign in to comment.