javaresthttppostopenhab

The UI can't control the Philips Hue Color lightbulb


I am trying to make OpenHAB control a Philips Hue Color light bulb. I have used help of a friend in some of the files however still can't control it using the UI. Here's what exists in pi@raspberrypi:/opt/openhab/configurations/sitemaps $ vim iotpi.sitemap:

sitemap demo label="Main Menu"
{

        Frame label="Lights" {
                Switch         item=Toggle_1                                label="Garage"
                Colorpicker    item=Color_1    visibility=[Toggle_1==ON]    label="Garage Light Color"
                Slider         item=Dimm_1     visibility=[Toggle_1==ON]    label="Garage Brightness"
                Slider         item=CT_Dimm_1  visibility=[Toggle_1==ON]    label="Garage Color Temperature"
        }  
} 

Here's what exists in pi@raspberrypi:/opt/openhab/configurations/rules $ vim iotpi.rules:

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.openhab.core.persistence.*



//var DecimalType hue = new DecimalType(240) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
//var PercentType sat = new PercentType(100) // 0-100
//var PercentType bright = new PercentType(100) // 0-100
//var HSBType light = new HSBType(hue,sat,bright)


rule "Garage Light"
when
    Item Toggle_1 received command
then
    if(receivedCommand==ON) {
        sendCommand(Toggle_1, ON)
        //sendHttpGetRequest("http://<ip_address>/cgi-bin/do?cmd=ir_code&ir_code=A05FBF00")
    } else if(receivedCommand==OFF) {
        // turn off Dune HD and AVR
        //sendHttpGetRequest("http://<ip_address>/cgi-bin/do?cmd=ir_code&ir_code=A15EBF00")
        sendCommand(Toggle_1, OFF)
    }
end

And here's what exists in my pi@raspberrypi:/opt/openhab/configurations/items $ vi iotpi.items:

Switch Toggle_1   "Garage bulb"   (Switching) {hue="3"}
Color Color_1     "Garage bulb"   (Colorize)  {hue="1"}
Dimmer Dimm_1     "Garage bulb"   (WhiteDimmer)   {hue="1;brightness;30"}
Dimmer CT_Dimm_1      "Garage bulb"   (CTDimmer)  {hue="1;colorTemperature;30"}

Also I have the following in both openhab.cfg and openhab_default.cfg files in configuration folder:

hue:ip=192.168.1.105
hue:secret=openHABRuntime
hue:refresh=10000

I am not sure what are the missing parts and why the hue cannot be controlled by OpenHAB UI that is being run on Raspberry Pi 2 Model B.

When I browse the Pi IP, The following toggles without me interrupting, I am not sure who is sending ON/OFF commands to the UI as it is changing every few seconds without my interruption. enter image description here

enter image description here

This is what events.log in openhab log folder shows:

2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:40 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command OFF
2016-03-22 23:39:41 - Toggle_1 received command ON
2016-03-22 23:39:41 - Toggle_1 received command OFF
2016-03-22 23:39:41 - Toggle_1 received command OFF
2016-03-22 23:39:41 - Toggle_1 received command OFF
2016-03-22 23:39:41 - Toggle_1 received command OFF
2016-03-22 23:39:41 - Toggle_1 received command OFF

And here's a few of lines from another log file 2016_03_22.request.log:

0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:41 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 2310
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:42 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 1925
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:43 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:43 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:44 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:44 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:45 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:45 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:46 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:47 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:47 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:48 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:48 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 644
0:0:0:0:0:0:0:1 -  -  [22/Mar/2016:23:40:49 +0000] "GET /openhab.app?sitemap=iotpi&poll=true&__async=true&__source=waHome HTTP/1.1" 200 2310

Finally:

pi@raspberrypi:/opt/openhab/logs $ vi openhab.log 

2016-03-22 23:35:07.415 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.8.1).
2016-03-22 23:35:14.419 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
2016-03-22 23:35:14.606 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
2016-03-22 23:35:21.676 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'demo.script'
2016-03-22 23:35:23.349 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist'
2016-03-22 23:35:23.484 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'logging.persist'
2016-03-22 23:35:23.550 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'db4o.persist'
2016-03-22 23:35:23.586 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'exec.persist'
2016-03-22 23:35:23.736 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'iotpi.items'
2016-03-22 23:35:23.872 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'demo.items'
2016-03-22 23:35:34.028 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
2016-03-22 23:35:34.783 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'demo.sitemap'
2016-03-22 23:35:35.405 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'iotpi.sitemap'
2016-03-22 23:35:35.459 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'buiten.sitemap'
2016-03-22 23:35:39.918 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /classicui/openhab.app
2016-03-22 23:35:46.003 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'zwave.rules'
2016-03-22 23:35:46.977 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'demo.rules'
2016-03-22 23:36:04.466 [WARN ] [.o.c.p.e.PersistenceExtensions] - There is no queryable persistence service registered with the name 'rrd4j'
2016-03-22 23:36:04.478 [ERROR] [m.r.internal.engine.RuleEngine] - Error during the execution of startup rule 'Update max and min temperatures': cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null
2016-03-22 23:36:04.494 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'iotpi.rules'
2016-03-22 23:36:04.610 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'hue.rules'
2016-03-22 23:36:04.869 [INFO ] [.service.AbstractActiveService] - NTP Refresh Service has been started
2016-03-22 23:36:05.021 [INFO ] [.service.AbstractActiveService] - HTTP Refresh Service has been started
2016-03-22 23:36:06.127 [INFO ] [.p.rrd4j.internal.RRD4jService] - Removing invalid defintion component = null heartbeat = 0 min/max = 0.0/0.0 step = 0 0 archives(s) = [] 0 items(s) = []
2016-03-22 23:36:12.314 [INFO ] [.service.AbstractActiveService] - Hue Refresh Service has been started
2016-03-22 23:36:13.497 [INFO ] [g.openhab.model.script.Weather] - Temperature evolved of 0 degrees.
~                                                                                                       

Here's the link to my github of the latest OpenHAB as described in this problem: https://github.com/lamiastella/OpenHAB


Solution

  • Solved the problem by deleting the iotpi.rules in rules directory. It was causing the toggle. However I still can't control the philips hue using UI.

    UPDATE: I used a hack, that was changing the secret key and running it again and then pairing hue again with openhab. Somehow hue pairing was lost!