Jump to content

HC3 send data to url on trigger


Recommended Posts

My goal is to send device changes from +- 20 fibaro devices to another api system. My devices are motion sensors, door sensors, smoke sensors and wallplugs.

 

I started to make a lua script:

{
    operator = "any",
    conditions = 
    {
        {
            type = "device",
            id = 21,
            property = "value",
            operator = "anyValue",
            isTrigger = true
        },
        {
            type = "device",
            id = 24,
            property = "value",
            operator = "anyValue",
            isTrigger = true
        }
    }
}

How to make this script more generic, for example a script that triggers on every change in a range of devices? is that possible.

For example for device 1, 2, 7 and 10 a http request must be send when data changed for motion, light or temperature?

 

In the action i started a Quickapp, because i can't find a way to send direct http commands here:

fibaro.call(25, "turnOn")

How to get the ID and the VALUE this scripts is triggered from?

 

After that i make a Quickapp:

function QuickApp:turnOn()
    self:debug("binary switch turned on")
    self:updateProperty("value", true)
    self:fcCommands("true")
end

function QuickApp:turnOff()
    self:debug("binary switch turned off")
    self:updateProperty("value", false)    
    self:fcCommands("false")
end

function QuickApp:fcCommands(cmd)
    local address = "http://USER:[email protected]/scada-remote/request.cgi?m=json&r=grp&fn=write&alias=KNXGROUP&value=" ..cmd
    self.http:request(address, {
        options={
            headers = { 
                Accept = "application/json"
            },
            checkCertificate = true,
            method = 'GET'
        },
        success = function(response)
            self:debug("response status:", response.status) 
            self:debug("headers:", response.headers["Content-Type"]) 
            local data = json.decode(response.data)
        end,
        error = function(error)
            self:debug('error: ' .. json.encode(error))
        end
    }) 
end

function QuickApp:onInit()
    self:debug("onInit")
    self.http = net.HTTPClient({timeout=3000})
end

But now i get a http 401, how to solve this?

 

Anyone a better or more generic way to send data to another system with a api request?

Edited by GJ Niewenhuijse
Link to post
Share on other sites

Here is a QA that could inspire you. It sends all events to external systems subscribing to events. Like webhook.

you could filter the events on your list of devices before pushing them.

 

Link to post
Share on other sites
2 hours ago, GJ Niewenhuijse said:

How to make this script more generic, for example a script that triggers on every change in a range of devices? is that possible.

For example for device 1, 2, 7 and 10 a http request must be send when data changed for motion, light or temperature?

 

a multitigger with scene (power and state from dev 885, state from 939, any button click with centralscene dev, any button from sceneactivation dev, autostart after reboot and manually started)

 

{
  conditions = { {
      type = "se-start",
      property = "start",
      operator = "==",
      value = true,
      isTrigger = true
    },{
      type = "manual",
      property = "execute"
    },
    {id = 885, isTrigger = true, operator = "anyValue", property = "value", type = "device"},
    {id = 885, isTrigger = true, operator = "anyValue", property = "power", type = "device"},
    {id = 939, isTrigger = true, operator = "anyValue", property = "value", type = "device"},
    {id = 850, isTrigger = true, operator = "anyValue", property = "centralSceneEvent", type = "device"},
    {id = 656, isTrigger = true, operator = "anyValue", property = "sceneActivationEvent", type = "device"}
    },
  operator = "any"
}

 

Quote

How to get the ID and the VALUE this scripts is triggered from?

 

of course one need later in scene code check the trigger

 

local trigger = sourceTrigger

if trigger.type == 'se-start' or trigger.type == 'user' then
  
if sourceTrigger.property == "sceneActivationEvent" then
    
if sourceTrigger.property == "centralSceneEvent" then

 

of course there is limitation with scene instances, so the code need to be fast or async to not miss events ...

 

Quote

Anyone a better or more generic way to send data to another system with a api request?

 

the idea @jgab posted is actually much better, than a scene, because it does change with single instance any change. The same is being used in e.g. InitialState plugin, and it works very well, so for small integration one can work with scene, with larger of course with more scenes - or single QA.

 

Quote
    local address = "http://USER:[email protected]/scada-remote/request.cgi?m=json&r=grp&fn=write&alias=KNXGROUP&value=" ..cmd

 

 

KNX 😈

Edited by tinman
Link to post
Share on other sites
17 hours ago, jgab said:

Here is a QA that could inspire you. It sends all events to external systems subscribing to events. Like webhook.

you could filter the events on your list of devices before pushing them.

 

Thanks, that looks like the solution. But how to easely filter events?

 

For example i like to get value changes for device 21 and 24 and battery changes for devices 21:

deviceEvents = 
{
   [21] = {'value','battery'}, 
   [24] = {'value'}
}
Edited by GJ Niewenhuijse
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...