dastrix80
(Kris K)
January 27, 2019, 3:38am
1
Hi Guys
Does anyone use a dashboard menu within habpanel like this? I find when changing dasboards, not always, it wont change unless I go to another dashboard before going to the one I want.
Ie: Changing from System to Entertainment won’t work, unless I change to Cameras before Entertainment.
Very odd! I’m using a Samsung Tablet, Tab A 8.0 . Screenshot from a PC, not on the Tablet to show the dashboards using the menu_page switch item.
I’m using this code in the Widget
<div class="section">
<div class="controls">
<div class="title">Dashboards</div>
<div class="widget.wide">
<div class="controlGroup">
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='System']" ng-click="sendCmd('MENU_page', 'System')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#controal-4"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Lighting']" ng-click="sendCmd('MENU_page', 'Lighting')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/matrixicons.svg#light_bulb"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Entertainment']" ng-click="sendCmd('MENU_page', 'Entertainment')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#box"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Comfort']" ng-click="sendCmd('MENU_page', 'Comfort')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#thermometer-3"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Gate & Garage']" ng-click="sendCmd('MENU_page', 'Gate & Garage')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#garage"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Temp']" ng-click="sendCmd('MENU_page', 'Temp')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#celsius"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Cameras']" ng-click="sendCmd('MENU_page', 'Cameras')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#cam-4"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Irrigation']" ng-click="sendCmd('MENU_page', 'Irrigation')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#drops"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Power Usage']" ng-click="sendCmd('MENU_page', 'Power Usage')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#thunder-1"></use></svg></div>
</div>
</div>
</div>
</div>
Cheers
Open up developer tools (usually F12), recreate the issue, then post console logs.
dastrix80
(Kris K)
January 29, 2019, 9:13pm
3
thanks luckymallari, ill try that.
dastrix80
(Kris K)
January 29, 2019, 11:32pm
4
Had a look through this, not specifically stood out.
When I went to my weather dashboard, I saw these errors but I dont feel they are related to my issue.
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
registerEventSource/source.onmessage@https://openhab/habpanel/app/services/openhab.service.js:176:33
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
e/q<@https://openhab/habpanel/vendor/vendor.js:160:386
f@https://openhab/habpanel/vendor/vendor.js:45:490
mg/k.defer/c<@https://openhab/habpanel/vendor/vendor.js:48:418
vendor.js:119:446
Command sent: MENU_page=Temp openhab.service.js:75:17
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
l@https://openhab/habpanel/vendor/vendor.js:99:192
K@https://openhab/habpanel/vendor/vendor.js:103:376
tg/</N.onload@https://openhab/habpanel/vendor/vendor.js:104:338
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
e/q<@https://openhab/habpanel/vendor/vendor.js:160:386
f@https://openhab/habpanel/vendor/vendor.js:45:490
mg/k.defer/c<@https://openhab/habpanel/vendor/vendor.js:48:418
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
e/v.$$intervalId<@https://openhab/habpanel/vendor/vendor.js:109:167
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
e/q<@https://openhab/habpanel/vendor/vendor.js:160:386
f@https://openhab/habpanel/vendor/vendor.js:45:490
mg/k.defer/c<@https://openhab/habpanel/vendor/vendor.js:48:418
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
e/v.$$intervalId<@https://openhab/habpanel/vendor/vendor.js:109:167
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
compile/</p</<@https://openhab/habpanel/vendor/vendor.js:374:9055
e/q<@https://openhab/habpanel/vendor/vendor.js:160:308
f@https://openhab/habpanel/vendor/vendor.js:45:490
mg/k.defer/c<@https://openhab/habpanel/vendor/vendor.js:48:418
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
e/q<@https://openhab/habpanel/vendor/vendor.js:160:386
f@https://openhab/habpanel/vendor/vendor.js:45:490
mg/k.defer/c<@https://openhab/habpanel/vendor/vendor.js:48:418
vendor.js:119:446
Loaded 402 openHAB items openhab.service.js:35:21
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
l@https://openhab/habpanel/vendor/vendor.js:99:192
K@https://openhab/habpanel/vendor/vendor.js:103:376
tg/</N.onload@https://openhab/habpanel/vendor/vendor.js:104:338
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
e/q<@https://openhab/habpanel/vendor/vendor.js:160:386
f@https://openhab/habpanel/vendor/vendor.js:45:490
mg/k.defer/c<@https://openhab/habpanel/vendor/vendor.js:48:418
vendor.js:119:446
Error: [sprintf] expecting number but found string
b.format@https://openhab/habpanel/vendor/vendor.js:365:1026
b@https://openhab/habpanel/vendor/vendor.js:365:108
@https://openhab/habpanel/vendor/vendor.js:536:83
recurse/<@https://openhab/habpanel/vendor/vendor.js:255:75
s/c<@https://openhab/habpanel/vendor/vendor.js:130:277
l/<@https://openhab/habpanel/vendor/vendor.js:128:439
$digest@https://openhab/habpanel/vendor/vendor.js:144:320
$apply@https://openhab/habpanel/vendor/vendor.js:147:361
e/v.$$intervalId<@https://openhab/habpanel/vendor/vendor.js:109:167
dastrix80:
sprintf
sprintf is used all over HabPanel
https://github.com/openhab/org.openhab.ui.habpanel/search?q=sprintf&unscoped_q=sprintf
Based on the link above, you can determine which widget might be causing it.
Command sent: MENU_page=Temp openhab.service.js:75:17
Error: [sprintf] expecting number but found string
The error was actually informative, although it doesn’t point exactly where. Tell me which widgets you have on the problematic page.
You angular piece is also incorrect:
ng-class="{true: 'on'}[itemValue('MENU_page')=='Power Usage']"
Above doesn’t make sense. What are you trying to do?
ng-class works like this:
ng-class="{ CLASSNAME: boolean }"
AngularJS is what HTML would have been, had it been designed for building web-apps.
Declarative templates with data-binding, MVC, dependency injection and great
testability story all implemented with pure client-side...
dastrix80
(Kris K)
January 30, 2019, 3:32am
6
Hi Luckymallari, thanks for your help
The intention is to switch dashboards, the tutorial on the forum showed using a dummy item (MENU_page) to switch dashboards with the code above.
The widget at fault is the Weather one, at least thats the widget that causes the raft of errors seen above.
Here is a Dashboard code, with the menu switching
here is how its visually used:
And the widget code that relates to the menu changing, this doesnt occur on other dashboards so I dont think the code is incorrect. Perhaps its something else inside the Weather Widget?
<div class="section">
<div class="controls">
<div class="title">Dashboards</div>
<div class="widget.wide">
<div class="controlGroup">
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='System']" ng-click="sendCmd('MENU_page', 'System')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#controal-4"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Lighting']" ng-click="sendCmd('MENU_page', 'Lighting')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/matrixicons.svg#light_bulb"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Entertainment']" ng-click="sendCmd('MENU_page', 'Entertainment')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#box"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Comfort']" ng-click="sendCmd('MENU_page', 'Comfort')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#thermometer-3"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Gate & Garage']" ng-click="sendCmd('MENU_page', 'Gate & Garage')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#garage"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Temp']" ng-click="sendCmd('MENU_page', 'Temp')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#celsius"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Cameras']" ng-click="sendCmd('MENU_page', 'Cameras')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#cam-4"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Irrigation']" ng-click="sendCmd('MENU_page', 'Irrigation')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#drops"></use></svg></div>
<div class="control" ng-class="{true: 'on'}[itemValue('MENU_page')=='Power Usage']" ng-click="sendCmd('MENU_page', 'Power Usage')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#thunder-1"></use></svg></div>
</div>
</div>
</div>
</div>
dheneghan
(Dave Heneghan)
January 30, 2019, 4:00pm
7
I use the exact same mechanism as you for my menu on HABPanel and was experiencing similar issues to you for a while. Your issue might not be the same but what I found was that HABPanel was not always getting the items; If the issue is fairly consistent try calling to <my_openhab_ip>:8080/rest/items directly (just using a web browser) and check that the full json is returned, what I discovered is that one of my bindings was causing an issue and the JSON was not always being returned in full - and therefore HABPanel did not know of the updated Item state.
By the way - I like the layout of your weather; would you be prepared to share?
dastrix80
(Kris K)
January 30, 2019, 7:49pm
8
Ive seen issues like that in the past Dave , ill see what I can find
Sure, here is the JSON file. The images are weatherunderground ones, it works well on PC but for some reason doesnt load very consistently on the tablet.
Temp.widget.json (17.7 KB)
CHecked the code. It is filled with these:
"{{'%.0f' | sprintf:itemValue('BOM_Temp_Max_2')}}
This assumes that itemValue(…) is a Number. Which is incorrect. If the item has no value it will be UNDEF, as in UNDEF as string. You are now passing string to sprintf with a '%.0f'
format. You cannot format a string with that. That’s why it throws an error. try doing it like this:
"{{'%.0f' | sprintf: ( +itemValue('BOM_Temp_Max_2') || 0 ) }}
The “+” is an implicit cast to number. The ||0 defaults it to zero for any error, such as “UNDEF”
Lots of errors on that file. For example:
ng-class="{true: 'on'}[itemValue('MENU_page')=='System']"
is incorrect and should be
ng-class="{'on' : itemValue('MENU_page')=='System'}"
As I said above, ng-class has this format:
{ 'CLASSNAME' : boolean }
dastrix80
(Kris K)
January 31, 2019, 4:15am
10
Hi Lucky
But BOM_Temp_Max_2 is a number, as seen here:
openhab> smarthome:status BOM_Temp_Max_2
25
openhab>
I’ve made your suggested changes to the MENUs, they still work Ill see if that resolves the issue.
That’s just one of them. There are multiple instances of sprintf in that file/code. You have to do my suggestion in every one of them
dastrix80
(Kris K)
January 31, 2019, 4:33am
12
No worries, ill look through them if theres a string ill modify it.
dastrix80
(Kris K)
January 31, 2019, 4:38am
13
How are you able to determine the item thats causing the error? The console doesnt show me the actual item name for me to fix. It just has:
Error: [sprintf] expecting number but found string
b.format@https://oh2.ddns.net/habpanel/vendor/vendor.js:365:1026
b@https://oh2.ddns.net/habpanel/vendor/vendor.js:365:108
@https://oh2.ddns.net/habpanel/vendor/vendor.js:536:83
recurse/<@https://oh2.ddns.net/habpanel/vendor/vendor.js:255:75
s/c<@https://oh2.ddns.net/habpanel/vendor/vendor.js:130:277
l/<@https://oh2.ddns.net/habpanel/vendor/vendor.js:128:439
$digest@https://oh2.ddns.net/habpanel/vendor/vendor.js:144:320
$apply@https://oh2.ddns.net/habpanel/vendor/vendor.js:147:361
e/q<@https://oh2.ddns.net/habpanel/vendor/vendor.js:160:386
f@https://oh2.ddns.net/habpanel/vendor/vendor.js:45:490
mg/k.defer/c<@https://oh2.ddns.net/habpanel/vendor/vendor.js:48:418
I never stated I know which item is causing it but I am 100% sure the issue lies with the use of the sprintf filter which is everywhere in the code. The argument given to sprintf is “%.0f” which will only accept numbers. So the error you see in logs is correct. So you need to change every line where Sprintf is used and add the error checking like I mentioned above
1 Like
dastrix80
(Kris K)
January 31, 2019, 4:47am
15
Thanks Lucky for being patient with me I’m looking through it now to see where sprintf might have been used for String values.
just saw this. Its probably because your item Menu Page will only change the page when it is CHANGED. not when it receives a command.
What usually happens is you open habpanel. and try to click on a page, but if the item Menu Page is already that state, it wont change the page in habpanel.
i created a rule that runs every time the item receives command, it waits a second,then updates the item with a null value. This doesn’t change the page in habpanel. but it means if i click the page that is already active, it will just reload the page.
Ahhhh. May you share your rule Christopher ? That sounds like exactly what I’m experiencing!
This is my rule. My item is set to HomePageItem
rule "ResetPage"
when
Item HomePageItem received command
then
Thread::sleep(2300)
HomePageItem.postUpdate("")
end
I also have this rule, which just updates another item, so i send a command to this item when i want sliders to update instantly, i.e, brightness sliders or volume sliders. There is an issue in habpanel where sliders only update and show their current values when any item receives a command in openhab.
rule "UpdatePage"
when
Item hpUpdateScreen received command ON
then
Thread::sleep(100)
hpUpdateScreen.postUpdate(OFF)
end
1 Like
Thanks thats fixed the issue! 1000% better. This should be a standard feature.
While i agree that it should be different. Its a simple fix.
What happens is the habpanel waits for an item state CHANGE event, not an item update event.
Hence why the simple rule that updates the item to null works.
Also. if this is fixed. maybe show my post as the solution.