openHAB + ThingSpeak

941 views
Skip to first unread message

belovictor

unread,
Jan 22, 2012, 1:48:30 PM1/22/12
to openhab
Hi,

Just wanted to share my experience of linking openHAB to ThingSpeak to
make historical stats for certain sensor values. I've done this using
drools in openHAB snapshot 0.9.

rule "Update house temperature to ThingSpeak"
when
$event : StateEvent(itemName=="House_Temperature")
then
sendHttpGetRequest("http://api.thingspeak.com/update?
key=<mykey>&field1=" + ((DecimalType)
$event.getNewState()).toString());
end

rule "Update outside temperature to ThingSpeak"
when
$event : StateEvent(itemName=="Weather_Temperature")
then
sendHttpGetRequest("http://api.thingspeak.com/update?
key=<mykey>&field2=" + ((DecimalType)
$event.getNewState()).toString());
end

You also need to add import function org.openhab.io.net.actions.HTTP.*
to imports section of your .drools file.

Works great, though I would prefer to have a ThingSpeak binding in
openHAB. Maybe adding it like thingspeak=field1 into the items
configuration and adding ThingSpeak key configuration to openhab.cfg
file. On the other hand having such functionality as historical
reporting inside openHAB for use in web and native user interfaces.
Then there will be enough to add some option, like reporting=yes, to
items configuration.

Just wanted to know if somebody works on something like that? If not,
I would give it a try myself then. And do you have any plans to add
some kind of persistent storage or database to openHAB which can be
used to store historical values?

Best regards,
Victor Belov


Kai Kreuzer

unread,
Feb 1, 2012, 5:02:10 PM2/1/12
to ope...@googlegroups.com
Hi Victor,

> Then there will be enough to add some option, like reporting=yes, to
> items configuration.
>
> Just wanted to know if somebody works on something like that? If not,
> I would give it a try myself then. And do you have any plans to add
> some kind of persistent storage or database to openHAB which can be
> used to store historical values?

Yes, definitely! We have http://code.google.com/p/openhab/issues/detail?id=21, which will deal with persisting historical data in different ways. This is THE major feature that I would like to add for the next release (1.0.0). ThinkSpeak might then be one of many "persistence providers" in this new framework - sounds good to me :-)

In the next few days I want to start a discussion around that here in the group, so stay tuned.

Regards,
Kai

Juanker Atina

unread,
Feb 2, 2012, 4:41:33 AM2/2/12
to openhab
Hi there, nice to hear about thingspeak stuff :)

I was playing a bit with these IoT platforms (pachube, thingspeak,
opensen.se) and i will post my results today or maybe tomorrow.


Regards.

On 1 feb, 23:02, Kai Kreuzer <k...@openHAB.org> wrote:
> Hi Victor,
>
> > Then there will be enough to add some option, like reporting=yes, to
> > items configuration.
>
> > Just wanted to know if somebody works on something like that? If not,
> > I would give it a try myself then. And do you have any plans to add
> > some kind of persistent storage or database to openHAB which can be
> > used to store historical values?
>
> Yes, definitely! We havehttp://code.google.com/p/openhab/issues/detail?id=21, which will deal with persisting historical data in different ways. This is THE major feature that I would like to add for the next release (1.0.0). ThinkSpeak might then be one of many "persistence providers" in this new framework - sounds good to me :-)

Victor Belov

unread,
Feb 2, 2012, 1:09:50 PM2/2/12
to ope...@googlegroups.com
Hi,

Well, while my post was moderated :-) I made some progress. First I
made it based on rules instead of drules (rules are available starting
from openhab 0.9). Then I discovered that when both temperatures come
from bus at the same time it does not work with ThingSpeak because
they have 1 request / 15 seconds limit for a data stream. So a
modified variant looks like this:

rule ThingSpeak
when
Item House_Temperature received update
then
sendHttpGetRequest("http://api.thingspeak.com/update?key=<ThingSpeak
key>&field1=" + House_Temperature.state.toString() + "&field2=" +
Weather_Temperature.state.toString());
end

And it just works. Another idea could be sending this values for
certain amount of sensors using simple crontab once every 1-5 minutes.
But this only works for numeric values, for movement sensor, for
example, you need to send the value as soon as you got update from the
bus or it will just be irrelevant :-)

I used ThingSpeak among others because of it's flexible and javascript
based (which means it work on iPad and iPhone too!) graph library.

Best regards,
Victor Belov

> --
> You received this message because you are subscribed to the Google Groups "openhab" group.
> To post to this group, send email to ope...@googlegroups.com.
> To unsubscribe from this group, send email to openhab+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/openhab?hl=en.
>

Reply all
Reply to author
Forward
0 new messages