In http://www.cpmills.com/2012/02/24/monitoring-temperatures-using-fhem-rrdtool-php-javascript I have attempted to describe how I am graphing my heating system using PHP, FHEM, RRDTool and JavaScript.

It seems that FHEM+PHP is a popular search term landing on my website so I wanted to explain in a little more detail how this part of the system works.

FHEM provides a really useful method of pulling out all the detail about all the devices it currently knows about through the simple command xmllist. Connecting to FHEM on port 7072 (or whatever you have configured) and sending the command xmllist will return a (presumably) well formed XML string which can then be parsed directly in PHP.

The code I’ve written is object oriented but don’t let that put you off. The essential activities are as follows:

  1. Connect to FHEM on it’s TCP port (usually 7072)
  2. send ‘xmllist\nquit\n’ to request the XML output and then immediately close the TCP connection.
  3. Retrieve the XML as it is returned.
  4. Create a new SimpleXMLElement using the XML obtained in 3 above as input.
  5. Extract the keys/values you are interested in using SimpleXMLElement->xpath.

The following (simple) example displays the current measured temperature in my kitchen:

In reality, you would want to add significant error checking to the above code to make it useful, but its a great start at obtaining detail from FHEM using PHP.

About the Author

chrisChris works as an IT Security Specialist for a large FTSE 100 company. He is a geek at heart and loves nothing more than trying to automate his home. The problem is, his wife simply doesn't get it and can't understand why they can't have 'normal' lights like everyone else! Chris is dedicated therefore to implementing automation in a family friendly way.View all posts by chris →

Leave a Reply