Sum (and chart) all switched on lights

906 views
Skip to first unread message

Cyril Jaquier

unread,
May 8, 2013, 3:23:40 AM5/8/13
to ope...@googlegroups.com
Hi all,

I'm experimenting a bit more with openHAB and would like to chart the number of switched on lights over time. I tried different things like:

Group:Switch:SUM(ON,OFF)    Lumiere_Chart    "Lumières"
or
Group:Number:SUM    Lumiere_Chart    "Lumières"

but "Lumiere_Chart" does not change its state. The persistence part is currently not a problem. I should see my "Lumiere_Chart" item getting updated. Here is the relevant part of my items:

Switch Lumiere_SS_Garage_Plafond    "Plafond"                (Garage, Lumiere_SS, Lumiere_Chart)
Switch Lumiere_SS_Garage_Etabli        "Etabli"                (Garage, Lumiere_SS, Lumiere_Chart)

So how do you do this? Thank you.

Regards,
Cyril

Kai Kreuzer

unread,
May 8, 2013, 3:41:37 PM5/8/13
to ope...@googlegroups.com
Hi Cyril,

Here is what you can do (based on the demo setup):

Add an item

Number NoOfLights

and make sure you persist it with rrd4j. Then create a rule like:

rule "Set number of lights"
when
Item Lights received update
then
NoOfLights.postUpdate(Lights.getStateAs(NoOfLights.acceptedDataTypes.get(0)))
end

The part "NoOfLights.acceptedDataTypes.get(0)" is only a workaround for "DecimalType" - out of some reason, putting "DecimalType" is not accepted here…

Now you can simply add a chart in your sitemap:

Chart item=NoOfLights period=D

That's it! Please note that as we use a number item, rrd4j does treat the values as floating point and not discrete numbers. That means that if you have 1 light on for 30 seconds and two lights for the next 30 seconds, you will see the line at 1.5 in the graph for this minute (which is the minimal resolution). But I think this should be fine for your use case.

Best regards,
Kai

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

Cyril Jaquier

unread,
May 9, 2013, 5:58:39 AM5/9/13
to ope...@googlegroups.com
Thank you Kai. I will try your solution. This is actually just a test so the 1.5 is fine.

However, I would have expected to be able to do this without any rules. Could you tell me if this is possible? Or said differently, could you explain or point me to some documentation about the expected behavior of Group:Number:SUM, Group:Switch:SUM, etc?

A detailed documentation about the items and sitemap file syntax would be of great help ;-)

Regards,
Cyril

Kai Kreuzer

unread,
May 11, 2013, 4:48:44 PM5/11/13
to ope...@googlegroups.com
Hi Cyril,

However, I would have expected to be able to do this without any rules. Could you tell me if this is possible?

Not in the past, but now it is - I have just pushed a change that makes this possible: https://code.google.com/p/openhab/source/detail?r=5f026f2f38e156c3df8678f9bd94f38f7cb2c476

Using a Group:Number:SUM should give the result you are asking for!

Best regards,
Kai

Cyril Jaquier

unread,
May 13, 2013, 2:04:10 AM5/13/13
to ope...@googlegroups.com
Hi Kai,

That's good news :-) Thank you. I will give it a try.

Regards,
Cyril
Reply all
Reply to author
Forward
0 new messages