Sensor for http switch (ESP8266)

I have ESP8266 switch which i have flashed with nodelua firmware and enabled it for 3 commands


in Openhab i am using

Switch wifiswitch1 “switch 1”

Switch item=wifiswitch1


rule “wifiswitch1”

    Item wifiswitch1 received command
    switch(receivedCommand) {
        case ON : sendHttpGetRequest("http://<ip>/?pin=on")
        case OFF : sendHttpGetRequest("http://<ip>/?pin=off")


all the above works perfectly fine …

my question is how can i create a sensor which will use actual “http:///?pin=status” and update the wifiswitch1 state based on real value from status command. The reason is that there are external command which are switching this wifiswitch on and off besides openhab like the Rf remote buttons.

openHAB itself has a REST API that your ESP8266 can be programmed to post to when the switch changes. If using OH 2 see the REST API docs that come with the install, or install them using PaperUI. If using OH 1.8, see the wiki.

Hi Rich,

thanks for the pointer i will try it out.

But on the other hand i was thinking not to have need to write code into ESP 8266 as its been programmed for responding to /?pin=status query so more was trying to establish query request from OpenHAB to make openHab configuration independent of ESP code.

Last evening i configured my zwave hardware switch which updates VERA of its states changes and Openhab receives the updates on each button press via mios binding it works very well but i am assuming the mios binding is doing a pull from VERA on state change of the switch right ? i want to implement similar for ESP as the binding doesn’t exist so a basic sensor would be good.

Actually I think the Vera is configured to push the updates to the MiOS binding.

Regardless, to poll you just set the refresh rate for the URL of the ESP’s API in the HTTP binding config to be how often you want to poll your devices for updates.

See the HTTP Binding wiki page for how to configure the binding appropriately.

However, if you can’t use the HTTP binding because you need to provide a body in the request, you will need to create a rule using a Timer cron trigger. This rule will execute every so often, as dictated by the cron expression, and pull the current state as desired.

The faster you poll the more responsive the update will be detected but also the more network and CPU you will consume doing nothing most of the time (this is why polling is usually frowned upon unless there is no other alternative). Often to poll frequently enough to get a rapid update means overwhelming the processor or network on constrained devices like an ESP8266.

HI Rich,

thanks for your comment, i 100% agree polling is not the best way … i will try and modify the esp firmware to send updates. Do you think is there a way to broadcast update and openhab can pick up somehow without any hardcoding of openhab into ESP stack ? ( i see the openhab picks up updates from my lightwaverf bridge even when its native app operates the the switch … i assume the reason is that its a UDP broadcast over network).

Also my http binding is not working … somehow i always get the following error -

2016-10-18 02:56:01.689 [DEBUG] [org.openhab.binding.http ] - ServiceEvent REGISTERED - {org.openhab.model.item.binding.BindingConfigReader, org.openhab.binding.http.HttpBindingProvider}={,,, service.bundleid=227, service.scope=bundle} - org.openhab.binding.http
2016-10-18 02:56:01.720 [ERROR] [org.openhab.binding.http ] - [org.openhab.binding.http(200)] bind method [addBindingProvider] not found; Component will fail
2016-10-18 02:56:01.722 [ERROR] [org.openhab.binding.http ] - [org.openhab.binding.http(200)] bind method [addBindingProvider] not found
2016-10-18 02:56:01.735 [ERROR] [org.openhab.binding.http ] - [org.openhab.binding.http(200)] unbind method [removeBindingProvider] not found; Component will fail

MQTT is probably your best bet.

There is likely a protocol there between the bridge and the binding that makes sure OH receives the updates. You have no such protocol in the ESP8266 unless you write one yourself. That would likely mean writing your own OH binding.

I am unfamiliar with error and have nothing to recommend.

Basically, yes. It’s using an event-driven long-poll from the MiOS/Vera unit. When something changes, the long-poll breaks out with a JSON containing the changes.

1 Like