Show the behavior of a "String" item in a chart with rrd4j

Is it possible to plot the history of string values in charts? I use rrd4j for persistence. With that I persist a
string item. Concrete, what I want to show in the chart, is the behavior of the “currentActivity” of the HarmonyHub Binding:

String	Harmony_Activity	"Harmony Activity [%s]"		<harmony_logo>	(gHarmony)	{channel="harmonyhub:hub:HAP-HarmonyHub:currentActivity"}

Harmony_Activity can e.g. have the following values:

  • TV
  • PS4
  • Radio

Now I would like to show on the time axis, which activity was when active. This could be only one line that can take multiple values, or it could be one line for each value that knows only 0/1. Doesn’t matter…

Does anyone have any ideas if this is possible, or maybe even an example?

I’ve only problem with this special chart. I have no problems with charts that represent number items.

Thank you all for your help

No rrd4j only supports Numbers. So you have to choose an other persistence like influxDB.

Why not create a dummy item?

When Harmony_Activity changed
Then 
If Harmony_Activity = tv
 Then dummy_item = 1
Elseif Harmony_Activity = radio
Then dummy_item = 2
Etc

Ps, this is not correct code, just showing the logic. Typing from my phone

Instead of using a proxy item, you could also use numbers in general and transform then to the strings you want. You wouldn’t have to write an additional rule then.

But in both cases your chart would only display numbers. So i’d say switching to a different persistence service would be the best way. Especially if you want to increasethe WAF of your system :wink:

You could also use 2 map transformations one two transform the state string into a number and save that in a Number item and then one for the map and remap the number to the activity.

Not tested, just an idea.

Wow, thank you guys for this great ideas. I think I will try something with dummy items and rules. I will post my solution here later…

With your tips I could do exactly what I wanted to do:

And here is the solution, how I did the configuration:

items-file:

String		Harmony_Activity		"Harmony Activity [%s]"		<harmony_logo>	(gHarmony)		{channel="harmonyhub:hub:HAP-HarmonyHub:currentActivity"}
Number		ChartHarmony_Period		"Harmony - Periode"		<line>
Number		Harmony_Activity_TV		"Samsung TV"					(gHarmonyActivity)
Number		Harmony_Activity_Radio		"Radio"						(gHarmonyActivity)
Number		Harmony_Activity_PS4		"PS4 pro"					(gHarmonyActivity)
Number		Harmony_Activity_ATV_Pic	"Apple TV"					(gHarmonyActivity)
Number		Harmony_Activity_ATV_Mus	"Apple TV Musik"				(gHarmonyActivity)

sitemap-file:

Text label="Grafiken - Harmony Activities" icon="line" {
	Switch item=ChartHarmony_Period mappings=[0="1h", 1= "4h", 2="1T", 3="1W"]
	Chart item=gHarmonyActivity period=h refresh=6000 visibility=[ChartHarmony_Period==0]
	Chart item=gHarmonyActivity period=4h refresh=30000 visibility=[ChartHarmony_Period==1, ChartHarmony_Period=="Uninitialized"]
	Chart item=gHarmonyActivity period=D refresh=30000 visibility=[ChartHarmony_Period==2]
	Chart item=gHarmonyActivity period=W refresh=30000 visibility=[ChartHarmony_Period==3]
}

rule-file:

rule Harmony_Activities
when 
	Item Harmony_Activity received update
then 
	if(Harmony_Activity.state == "PowerOff") {
		postUpdate(Harmony_Activity_TV, 0);
		postUpdate(Harmony_Activity_Radio, 0);
		postUpdate(Harmony_Activity_PS4, 0);
		postUpdate(Harmony_Activity_ATV_Pic, 0);
		postUpdate(Harmony_Activity_ATV_Mus, 0);
	} else if(Harmony_Activity.state == "Fernsehen (Samsung TV)") {
		postUpdate(Harmony_Activity_TV, 1);
		postUpdate(Harmony_Activity_Radio, 0);
		postUpdate(Harmony_Activity_PS4, 0);
		postUpdate(Harmony_Activity_ATV_Pic, 0);
		postUpdate(Harmony_Activity_ATV_Mus, 0);
	} else if(Harmony_Activity.state == "Radio Analog") {
		postUpdate(Harmony_Activity_TV, 0);
		postUpdate(Harmony_Activity_Radio, 1);
		postUpdate(Harmony_Activity_PS4, 0);
		postUpdate(Harmony_Activity_ATV_Pic, 0);
		postUpdate(Harmony_Activity_ATV_Mus, 0);
	} else if(Harmony_Activity.state == "PS4 Wiedergabe") {
		postUpdate(Harmony_Activity_TV, 0);
		postUpdate(Harmony_Activity_Radio, 0);
		postUpdate(Harmony_Activity_PS4, 1);
		postUpdate(Harmony_Activity_ATV_Pic, 0);
		postUpdate(Harmony_Activity_ATV_Mus, 0);
	} else if(Harmony_Activity.state == "Fernsehen (Apple TV)") {
		postUpdate(Harmony_Activity_TV, 0);
		postUpdate(Harmony_Activity_Radio, 0);
		postUpdate(Harmony_Activity_PS4, 0);
		postUpdate(Harmony_Activity_ATV_Pic, 1);
		postUpdate(Harmony_Activity_ATV_Mus, 0);
	} else if(Harmony_Activity.state == "AppleTV Musik") {
		postUpdate(Harmony_Activity_TV, 0);
		postUpdate(Harmony_Activity_Radio, 0);
		postUpdate(Harmony_Activity_PS4, 0);
		postUpdate(Harmony_Activity_ATV_Pic, 0);
		postUpdate(Harmony_Activity_ATV_Mus, 1);
	}
 end
1 Like

@Harphme the rule can be optimized. Just set all to zero before the ifs. Then use a switch case instead of the ifs and just set the item you want. So it is a lot easier to adjust or add more and less code.

Not Tested, but something like this.

rule Harmony_Activities
when 
    Item Harmony_Activity received update
then 
    postUpdate(Harmony_Activity_TV,     0)
    postUpdate(Harmony_Activity_Radio,  0)
    postUpdate(Harmony_Activity_PS4,    0)
    postUpdate(Harmony_Activity_ATV_Pic,0)
    postUpdate(Harmony_Activity_ATV_Mus,0)

    switch Harmony_Activity.state {
        case "PowerOff"               : 
        case "Fernsehen (Samsung TV)" : postUpdate(Harmony_Activity_TV,     1)
        case "Radio Analog"           : postUpdate(Harmony_Activity_Radio,  1) 
        case "PS4 Wiedergabe"         : postUpdate(Harmony_Activity_PS4,    1)
        case "Fernsehen (Apple TV)"   : postUpdate(Harmony_Activity_ATV_Pic,1)
        case "AppleTV Musik"          : postUpdate(Harmony_Activity_ATV_Mus,1)
    }
 end
2 Likes