[SOLVED] goToDashboard instead of Switch Dashboard item

Hi,
i was wondering if i can use somehow ng-click=“goToDashboard(dash.id)”, which i found in the drawer.tpl.html in an widget so i do not need to use the “Switch dashboard with item value” item/function?

the reason is that if i use items in my dashboard headed using the “Switch dashboard with item value” and changing then dashboard via the drawer i may have a problem to switch back to the previous dashboard by using the header icon since the “Switch Dashboard item” has still the same state

for example i have a Item in the header to go to the dashboard “Main” - Switch Dashboart item" (HABDash) changed to Main and the corresponding Dashboard gets open.

now i use the Drawer to to to dashboard “Weather” - (HABDash swould be still set to “Main”)
now if i would click on my header item to change to Main would not have any effect since HABDash is still “Main”

hope that make any sense to someone :thinking:

2 Likes

if you want to simply just go to a dashboard, you can have a custom widget like a link that goes to your dashboard id:

<a href="#/view/_YOUR_DASHBOARD_ID_>Click me</a>

example:

<a href="#/view/MAIN>Click me</a>

will activate/navigate MAIN dashboard.

The issue here is that $rootScope.settings.dashboard_control_item change will only trigger on an actual state change (ItemStateEvent or ItemStateChangedEvent). Since your HADBash item is still on “Main” this will not trigger.

Another ‘hackish’ thing you can do is make a rule to set your HABDash to an empty string.

rule "Reset HABDash"
when
    Item HABDash changed
then
    if (HABDash.state != "") {
        HABDash.sendCommand("")
    }
end

How above works:
When your HABDash changes to “MAIN”, it will switch right away to “” (empty string). I don’t think there’s a need for a delay here since the change to MAIN will be raised in the EventSource (from /rest/events). If it is already empty, it will ignore.

Since this code checks for the validity of the state, an empty string will not cause HABPanel to switch:
(openhab.service.js):

if (item.state && $rootScope.settings.dashboard_control_item === item.name) {
    console.log('Dashboard control item state changed, attempting navigation to: ' + item.state);
    $location.url('/view/' + item.state);
}

EDIT: Tagging @ysc if he has a better approach.

1 Like

@luckymallari thanks for yout tips. just implemented the rule you mentioned and it woks perfectly :+1: