Page - Reload is changing state back to default (ui-template,DB2)

Hi, this scenario might have been asked already but I could not find it

I'm currently migrating to DB2 and want to create a default header for all my switches and lights.
image

Unfortunatelly, any page-refresh (F5 or moving away and back to this page) will reset to above default state

Example:

  1. Page is newly loaded .. showing default state
    image

  2. Switch the light ON by clicking the "ON" button
    image

  3. pressing F5 / refresh the page .. resetting to default
    image

Please see code for ui-template here
header.json (4.2 KB)

How can I ensure that the state is maintained and only changed by user click on any of the elements?

thank you for your help

When you refresh the page the last message received by or sent by the template is replayed to the template. You have to ensure that the message you send includes information needed to correctly show the state.

If you add, in your template, in the watch msg function the line

console.log(`Message received: ${JSON.stringify(this.msg)}`)

and view the developer console in the browser then you will what message is being sent when you refresh the page.

Hi Colin,

I did add the line, but there is no debug output when a page refresh(F5) is happening ..looks like there is no update/change to "msg" while refresh :frowning:
image

I did the same in the aree to check when btn is clicked .. and output is showing for that

Any other idea?

Have you been able to see the same on your end when using my json code?

Can you post your updated flow please. Please post it inline rather than a file. In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

See this post for more details - How to share code or flow json

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.