Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
Adam.Bewsher 2
Hi everyone,
I've noticed a few places on the forum and spoken with a couple of people who have had issues with using HTML entities in virtual devices. This thread explains the workaround.
What is an HTML entity?
(From
Please login or register to see this link.
)The problem in Virtual Devices
If you want to write a string or Lua code which has an HTML entity (like & for example) in it, it will work the first time you save the virtual device. But when you open the device, all the HTML entities will be decoded into their single character form - & will become &, > will become > etc. So the next time you save it, everything will break. In fact, it doesn't even need the semicolon, so > will also become >.
The workaround
Do you remember that mystical string we put at the end of some virtual device button code? It looks like this:
Please login or register to see this code.
This is a sequence of hexadecimal escape codes which represent the characters Carriage Return (CR) and Line Feed (LF) repeated twice. In other words, two new lines.
We can use hexadecimal escape sequences to represent any character. And... it just so happens that 0x26 represents the character &.
So, if we replace all the ampersands (&) in our strings with 0x26, then they will still be output as & but when they are loaded into the browser for editing they will appear as 0x26. And 0x26gt; will not be decoded into >.
For example:
Please login or register to see this code.
Should be written as:
Please login or register to see this code.
otherwise, when you save the virtual device and reload it, it will become:
Please login or register to see this code.
But what about Lua?
If you have some Lua code like this:
Please login or register to see this code.
You may find it clearer (and simpler) not to use hexadecimal escape codes, but to change it to this:
Please login or register to see this code.
All this is doing is breaking the string up and joining it back together again. But now instead of & it has &".."amp and so it will not decode.
And that's it!
Now you will be able to edit and save your virtual devices as much as you like - without strange things happening causing them to break.
Happy Automating!
Adam Bewsher
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.