External switch (i.e. web JSON)

Hi,

Is it possible to make an input that checks a web-page for on/off status - and from that create condition/actions ?

I am thinking something like this :

Input (trigger) checks a webpage (i.e. www.example.com/switch.php) - JSON-response could be “switch:0” or “switch:1”. This trigger is then used in a condition.

Thanks,
Martin

Yes it is possible. You can use luup.inet_wget(url) for this. See [url=http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_wget]http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_wget[/url]

If you know that the remote device will always return the same structure, you could use Lua’s string.match(…) function to capture the variable rather than parse the whole of the json.

Brilliant. Thanks :slight_smile:

  • okay - next question :wink:

I have created a scene that runs every 5 mins. to check a URL for a switch-state.
Can this state be used as a trigger directly in PLEG, or should I use luup-code in the same scene to create the wanted action?

I don’t know luup-code very well, so could someone give me an example on how to switch a fibaro-switch on/off using luup??

Thanks!,
Martin

I have created a scene that runs every 5 mins. to check a URL for a switch-state. Can this state be used as a trigger directly in PLEG, or should I use luup-code in the same scene to create the wanted action?

PLEG cannot read status or variables from a scene. You could set a state variable in some device and PLEG could see that as a Device Property. Otherwise use a real or virtual switch. PLEG can simply use that as a Trigger. The code to turn a switch on would be:

local dID = 123 -- Set to your switch device number luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="1"},dID)

or to turn it off:

local dID = 123 -- Set to your switch device number luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="0"},dID)

Thanks - much appreciated!

/Martin