milo
(M)
1
Hello all,
I try to programm a Widget for my Main UI in OH3.4. For this I need a nested if else declaration. Here is my YAML
component: oh-label-card
config:
header: Active scene
icon: f7:sunrise
title: Active scene
footer: "=items.number_openhaboperatingmodus_dayphase.state === 0 ? 'Sunrise' : ( items.number_openhaboperatingmodus_dayphase.state === 1 ? 'Morning' : ( items.number_openhaboperatingmodus_dayphase.state === 2 ? 'Day' : ( items.number_openhaboperatingmodus_dayphase.state === 3 ? 'Sunset' : ( items.number_openhaboperatingmodus_dayphase.state === 4 ? 'Evening' : 'ndf'))))"
on: true
color: yellow
action: command
actionItem: Scene_General
actionCommand: "0"
slots: null
But it always shows “ndf” at the end. Is there anything I done wrong?
Thanks for the help
Mark_VG
(Mark)
2
What is the TYPE of your item? Maybe you need to compare to a string (“0”)?
milo
(M)
3
Here is my item description:
Number:Dimensionless number_openhaboperatingmodus_dayphase "[%d]"
I changed my YAML according openhab doc to
footer: "= (items.number_openhaboperatingmodus_dayphase.state === 0) ? 'Sunrise' : (items.number_openhaboperatingmodus_dayphase.state === 1) ? 'Morning' : (items.number_openhaboperatingmodus_dayphase.state === 2) ? 'Day' : (items.number_openhaboperatingmodus_dayphase.state === 3) ? 'Sunset': (items.number_openhaboperatingmodus_dayphase.state === 4) ? 'Evening' : (items.number_openhaboperatingmodus_dayphase.state === 5) ? 'Night' : 'Not Set'"
Now it shows again ‘Not Set’
If I set the title in my YAML
title: =items.number_openhaboperatingmodus_dayphase.state
is shows me 4
crnjan
(Crnjan)
4
AFAIK state
is a string regardless of item’s type, so in your case I guess “4”. You can either parse it to number
Number.parseInt(items.number_openhaboperatingmodus_dayphase.state) === 0
or compare it as a string
items.number_openhaboperatingmodus_dayphase.state === "0"
jstro
(John Strong)
6
Try it without the strict equality, i.e., use “==” instead of “===”. The triple equal sign requires the two quantities to be of the same type.