FHEM API

2,487 views
Skip to first unread message

rok

unread,
Oct 9, 2012, 8:49:07 AM10/9/12
to fhem-...@googlegroups.com
Hi, if I wanted to integrate some of the FHEM functionality into my existing web application written in Python, is there a FHEM api I can use?

I see there's several frontends for FHEM so I am assuming there must be something similar for these frontends to call FHEM backend commands?

Thanks!
Rok

drdownload

unread,
Oct 11, 2012, 1:04:27 AM10/11/12
to fhem-...@googlegroups.com
you can use json, telnet to interact with fhem, you name it

Rudolf Koenig

unread,
Oct 11, 2012, 2:27:13 AM10/11/12
to fhem-...@googlegroups.com
> you can use json, telnet to interact with fhem, you name it

Or to be more precise:
- there are two modules to contact fhem, either via simple TCP/IP (the module
is called telnet) or HTTP (FHEMWEB)
- both can be:
- configured to use encryption (SSL/HTTPS) and/or to require a password
- used the get detailed data via plain text (list), XML (XmlList) or JSon (JsonList)
- used to get a notification, if something has changed (plain text or JSonP)
- used to issue arbitrary fhem commands (plain text only)

There is also student project called TheOpenTransporter specifically designed
for frontends, although AFAIK it is not yet actively used.

rok

unread,
Oct 12, 2012, 8:44:48 AM10/12/12
to fhem-...@googlegroups.com
great, thank you! is there a list or some document on the FHEMWEB+json interface commands?

Rudolf Koenig

unread,
Oct 12, 2012, 9:59:12 AM10/12/12
to fhem-...@googlegroups.com
> great, thank you! is there a list or some document on the FHEMWEB+json
> interface commands?

not really, just try http://fhemhost:8083/fhem?cmd=jsonlist&XHR=1
and http://fhem.de/commandref.html#jsonlist

rok

unread,
Oct 15, 2012, 5:53:49 AM10/15/12
to fhem-...@googlegroups.com
So, what would be a command for turning on or off a FS20 device?

Rudolf Koenig

unread,
Oct 15, 2012, 6:04:07 AM10/15/12
to fhem-...@googlegroups.com
> So, what would be a command for turning on or off a FS20 device?

http://fhemhost:8083/fhem?cmd.Lamp=set%20Lamp%20off

Or set the redirectCmds FHEMWEB instance attribute to 0, switch a device, and
look at the URL in your browser.

rok

unread,
Oct 16, 2012, 4:40:14 PM10/16/12
to fhem-...@googlegroups.com
Rudolf, how come I cannot do this:
is there a different way of getting jsonlist with devspec over HTTP and in json format?

moreover, if i call a command like

the XHR command does not seems to yield any return at all. Is it possible to get a json response upon issuing a command?

On Monday, October 15, 2012 12:04:13 PM UTC+2, Rudolf Koenig wrote:
> So, what would be a command for turning on or off a FS20 device?

Rudolf Koenig

unread,
Oct 17, 2012, 4:32:16 AM10/17/12
to fhem-...@googlegroups.com
> Rudolf, how come I cannot do this:
> http://fhemhost:8083/fhem?cmd=jsonlist&XHR=1&devspec=<devicename> ?

Because it has the wrong format. Why don't you try my advice with redirectCmds?
Set this attribute to 0, type in the command in the FHEMWEB input field, and if
it works as expected, than add an &XHR=1 to the browser URL.
Your command should look like:
http://fhemhost:8083/fhem?cmd=jsonlist+devicename&XHR=1
See http://fhem.de/commandref.html#devspec for details.

Btw: jsonlist has a bug when specifying a devicespec which returns more than
one argument: it returns details only for the first one. Please consult the
author of JsonList (or fix the problem, and send the patches :)


> the XHR command does not seems to yield any return at all.

No return means OK, everything else is an error. Since specifying commands is
not implemented in a Json or Xml format, the answer is plain-text.

Or the other way round: For FHEMWEB everything is plain-text, and if a command
returns something, then it will display it. JSonList happens to return text
formatted as JSon, xmllist returns XML, and "set X Y" returns nothing on
success or an error (plain text).

rok

unread,
Oct 18, 2012, 2:34:09 AM10/18/12
to fhem-...@googlegroups.com
Yes, that works, thanks!

finally, would it make more sense for me to simply call the perl scripts from my python code? if so, would that be the 10_FS20.pm.FS20_Set  method? what about the "Get status" call?

I'll look into the devicespec problem, I only have one device now so waiting to receive the second one. If I fix the bug, where do I submit the patch?

Thanks a lot for your help,
Rok

Rudolf Koenig

unread,
Oct 18, 2012, 2:56:59 AM10/18/12
to fhem-...@googlegroups.com
> finally, would it make more sense for me to simply call the perl scripts
> from my python code?

No.

> If I fix the bug, where do I submit the patch?

Here in the group.
Reply all
Reply to author
Forward
0 new messages