How to define item states

Dear Experts,

I defined an Item without channel:
String DayOrNight “Day Or Light” <day_or_night>

I tried to set its state in a rule:
DayOrNight.state = ON

And got message:
Tried to set invalid state ON (OnOffType) on item DayOrNight of type StringItem, ignoring it

What I actually want to achieve is to set 2 states: Day/Night.

I know there are other ways to achieve this.
But is it possible to do it this way please?:innocent:

Thanks!

That sounds a lot like my “IsItDark” Item

Switch IsItDark <moon>

It is controlled by rules using the astro binding.

rule "Sunset"
when
    Channel 'astro:sun:local:civilDusk#event' triggered START
then
    IsItDark.postUpdate(ON)
end

rule "Sunrise"
when
    Channel 'astro:sun:local:civilDawn#event' triggered START
then
    IsItDark.postUpdate(OFF)
end
1 Like

Your item DayOrNight is of type string, but you try to apply a value ON (without “”), which is an openhab-special ENUM. Either you make DayOrNight a Switch:

Switch DayOrNight "Day or Light" <day_or_night>

or you set the state as a String in your rule:

DayOrNight.postUpdate("ON")

NOTE: you can’t (or maybe only shouldn’t) simply do DayOrNight.state = ON.

Sidenote: I doubt there is an icon in openhab called “day_or_night” - so unless you’ve added your own there will be nothing shown

1 Like

Thanks! This worked! :+1:
Couldn’t figure out of using postUpdate.