[SOLVED] Say() doesn't seem to work in switch case statement


(jimmy loyens) #1
  • Platform information:
    • Hardware: RPI3
    • OS: openhabian
    • Java Runtime Environment: oracle
    • openHAB version: OH 2.4.0

I want openhab to say something depending on the time of day. when i use the say() command by itself it works, but when i use it in a switch/case statement nothing is said?

rule "rule name"
when
    Item testSwitch changed from OFF to ON
then
setMasterVolume(1)
 //say("goede namiddag uwe majesteit","googletts:nlNLWavenetA", new PercentType(100)) // => this works
switch (vTimeOfDay){
    case "MORNING"      :   say("goede morgen uwe majesteit","googletts:nlNLWavenetA", new PercentType(100))
    case "PRENOON"      :   say("goede voormiddag uwe majesteit","googletts:nlNLWavenetA", new PercentType(100))
    case "NOON"         :   say("goede middag uwe majesteit","googletts:nlNLWavenetA", new PercentType(100))
    case "AFTERNOON"    :   say("goede namiddag uwe majesteit","googletts:nlNLWavenetA", new PercentType(100))
    case "EVENING"      :   say("goede avond uwe majesteit","googletts:nlNLWavenetA", new PercentType(100))
    case "NIGHT"        :   say("goede nacht uwe majesteit","googletts:nlNLWavenetA", new PercentType(100))
}
    
end 

allso tried

switch (vTimeOfDay){....}

I get the time of day var from a rule made with TimeOfDay design pattern. The rule works and returns a string vTimeOfDay.

I’ve searched the forum but can’t find a switch/case statement that uses a string. Am i missing something?

This is the items file:

String      vTimeOfDay          "Current time of day [%s]"
DateTime    vMorning_Time       "Ochtend [%1$tH:%1$tM]"
DateTime    vPreNoon_Time       "Voormiddag [%1$tH:%1$tM]"
DateTime    vNoon_Time          "Middag [%1$tH:%1$tM]"
DateTime    vAfternoon_Time     "Namiddag [%1$tH:%1$tM]"
DateTime    vEvening_Time       "Avond [%1$tH:%1$tM]"
DateTime    vNight_Time         "Nacht [%1$tH:%1$tM]"

(Jürgen Baginski) #2

If vTimeOfDay is an Item you should use vTimeOfDay.state (maybe with .toString, I’m not sure on that).


(jimmy loyens) #3

Indeed that did it. Thanks

It should indeed be vTimeOfDay.state