I wonder if it will be possible to have a settings string item that hold different gruop names?
Purpose is that I have a couple off different scenarios for my nightlight, one grup is all interior lights and all exterior lights and two other gruops containing different mixed items, then I have rules that fire on lux sensors changes and thresholds and send command on or off to a group, preferably easy configured under my settings in OH sitemap instead of chaning in code.
Sure, you can put anything you want into a String Item. But you’ll need a rule to interpret it. If you don’t want a rule, create different Groups for each scenario.
Sounds good, even thougfh my efforts are failing somewhere.
I have configuerd a variabel in rules file before all rules start
var duskgroup = lowsky
Then I have a rule that triggers when my settings Items changes, and settings item changes according to plan. Could’t be that what I hope i my global variable in first rows of rules file can’t be updated in a rule so that the rule just vreates a new variable?
If so which would be the best approach to handle that?
I already have different grops per my scenarios but I would like to easily change how much dusk lights that should be on.
rule "skymmningsgrupp ändrad"
when
Item dusk_group_string changed
then
var duskgroup = dusk_group_string.state
end
You are redefining the variable inside your rule. Only use var when creating a new variable. You’ve already created duskgroup so you don’t want to recreate it inside your rule.-
var duskgroup = dusk_group_string.state
with
duskgroup = dusk_group_string.state
but that trows an error in thedusk_light rule that’s supposed to use variable as actiongroup sendcommand. String items state seems valid
duskgroup.sendCommand(OFF)
error after dusk light action.
19:41:28.714 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Londonborg-3' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,org.openhab.core.types.Command) on instance: null in Londonborg
Result from log
19:50:19.157 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'dusk_group_string' received command sky
19:50:19.159 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'dusk_group_string' changed from lowsky to sky
19:50:19.160 [INFO ] [nhab.core.model.script.Skymmningsgrpp] - dusk_group_string.state:sky
rule "Skymmning av"
when
Item g1ManualDusk changed from ON to OFF
then
if(g1ManualDusk.state == OFF){
//sendBroadcastNotification("Manuell Skymmning av")
duskgroup.sendCommand(OFF)
//postUpdate(z33_scen, 3.0)
}
end
Hi I see your point but I’ve missed something in my explanation. dusk_group string is a stirng item that exist in my sitemaps settings section having for the moment two choices of groups for which items should be included in dusk light, hence the gruop isn’t allways the same. Now I need to go into rules file and change variable by hand to change duskgroup name.
To be successful it is vital you understand types.
As written (as best as I can piece it together because you’ve yet to post the full set of relevant code in context) the variable duskgroup starts out as a GroupItem as its type. Then in the original rule you reassign it the state of a StringItem which means duskgroup becomes of type StringType.
You cannot sendCommand to a StringType. It’s not an Item. It doesn’t even know what a command is.
In the second version of the rule, you set duskgroup to a String. Note that a String is not the same as a StringType and it most definitely is not a GroupItem. So, once again you cannot send a command to a String because a String doesn’t even know what a command is.
So, your options are to use the sendCommand Action that takes the name of an Item (sendCommand(dusk_group_string.state.toString), note that a StringType is not the same as a String so you must convert it to a String to use it here) like @CrazyElectron suggests, or modify your second rule (which really isn’t needed as illustrated here) to set duskgroup to the GroupItem, not a StringType nor a String (duskgroup = lowsky).
Thanks for all help now it works as it was intended, fylly if statement below in case someone else as same strange desire as me. Once again a thanks for helping out.