I try to set up a habpanel and show the current tv channel.
unfortunately my tv is not able to send out a string command but only on/off for single channels.
so i created a group “GrSender” that includes all of my channels.
Only one item of that group can be ON (the current channel you are watching).
Now i am looking for a way to plot the comment of the item that is ON into a string variable to display it in habpanel.
i hope it is clear what i am trying to achieve
Items file:
I finally had time to try it.
Very helpful link! Helps me with a lot of other stuff as well.
I am not sure how to do it. I understand the filter and i think it should result in the item that is ON.
Now the next problem: I do now have the item that’s on but i want to display the text of the label of that item.
i thought about posting the label to a sting var but i have no idea how to do that … ;-(
And i don’t know if my rule fires:
rule "Post Sender Name to String"
when
Item GrSender received update
or
Item GrSender received command
then
TV_String_Kanal.postUpdate(GrSender.filter[i|i.state==ON])
end
because i am looking on update or command change. does the group receive an update when one item is turned on but at the same time (is this even possible) another one is turned off? I configured the group as
Group:Switch:OR(ON,OFF).
Thank you! This will for sure help to trigger the rule
But i still can’t find a solution for transferring the label of the item that is ON to the string-var.
Inside your findfirst filter i just need to find the first item that’s on so i wrote:
…findFirst[state==ON] as GenericItem
but it’s not working. I’ll try a bit thanks!
i made some progress!
The filter works and when i use the log of your example and combining it with the additional filter of vzorglub it just plots the name - great so far!
but i am not able to store the filtered name of the val into a string.
sorry, i’m still a noob
my code:
rule "Post Sender Name to String"
when
//Item GrSender received update
//or
//Item GrSender received command
Time cron "0/1 * * * * ? *"
then
val triggeringTVchannel = GrSender?.members.filter[i|i.state==ON].forEach[j|
logInfo("Logger","Kanal: " + j.name.split("_").get(2))]
TV_String_Kanal.postUpdate(triggeringTVchannel.name.toString)
end
another question:
Where did you learn that stuff - i mean that split command for example.
For the items. I mostly used Item.state. is there really a command for Item.name and Item.label? Where can i read about that? Or is it just valid inside the filters?
rule "Post Sender Name to String"
when
//Item GrSender received update
//or
//Item GrSender received command
Time cron "0/1 * * * * ? *"
then
val triggeringTVchannel = GrSender?.members.filter[i|i.state==ON].forEach[j|
logInfo("Logger","Kanal: " + j.name.split("_").get(2))]
val channelName = j.name.split("_").get(2)
TV_String_Kanal.postUpdate(channelName)
end
I learned the same way as you as doing now, make rules and lots of mistakes
Looking in the community and docs and asking questions…
And reading the threads
Keep at it and you will be help someone one day
item.state and item.name as called properties (I think) not commands and return a value from the item
item.postUpdate or item.sendCommand are methods (like a function) and tell the item for do something
They are available from the openHAB docs
Unfortunately there is not label property for the reason given above
this means, you make a static variable (that’s val) and fill it with your logInfo Statement (that’s what you do with the forEach[...] syntax. That’s rubbish - I’m certain you’ll have some entries in your logs for this one!
If you’d like to have your channel logged and update your item:
GrSender?.members.filter[i|i.state==ON].forEach[j| // this is just a wrapper, it filters the member-items for stat==ON and make a forEach-statement for every item, which is ON
var String triggeringTVchannel = j.name.split("_").get(2) // writing the split-stuff in a _variable_
logInfo("Logger","Kanal: " + triggeringTVchannel) // logging that one
TV_String_Kanal.sendCommand(triggeringTVchannel) // updating the item (I guess, it's a Proxy item, so sendCommand is best) - as it is already a String, you want Need `toString` and as this one is a simple variable, you don't Need some Argument (which would give you the Name of the variable back, not the value nevertheless... ?)
]
PS: Two caveats with this:
if for some reason your ON-item.name doesn’t contain two “_” - the split will terminate with an ERROR
the variable “i” or “j” are created while the wrapper for “GrSender” is filled, so they only exist for filtering (i) and for the forEach-condition (j).
PS: how you learn that stuff? Getting a “programming for Dummies”-book or working intensively with existing Code and try to understand it!
A programming book for dummies is a good idea. Go for it.
I started 35 years ago copying manually printed BASIC (the language) programs into my father’s first PC at his work (256k memory and 1 floppy drive. When you stated the computer you had to put the OS floppy in first and then when loaded you could put you own 5 inch floppy for your own stuff… Great times)
There are also a lot of tutorials online.
Start with Python and/or JavaScript
Just further to this, I have a rule which switches off a group of lights. Rather than doing that, and potentially switching devices already off, to off, which seems like a waste of resources on the zwave network how would I be able to switch off, only members of the group which are switched on?
I saw Vincent’s post about
members.filter[i|i.state==ON].forEach[j|
However I’m wanting to use an IF statement, if if member of group is on, send it off.