FHEM Forum

FHEM => English Corner => Thema gestartet von: andyclimb am 01 Oktober 2016, 15:12:44

Titel: Create a hyperlink with userReadings?
Beitrag von: andyclimb am 01 Oktober 2016, 15:12:44
I've been struggling with this all day.  I'd like to create a hyperlink from userReadings..  take an IP from a reading and inject it into a URL that is then clickable from FHEM...  not joy..  can't even add a simple string...

I've done it previously with a value format for a readingsGroup like this

attr MQTT_IPs valueFormat <a href='http://$VALUE' target="_blank">$VALUE</a>



but I'd like it to appear now, in the readings list for the actual device...

I've tried


userReadings
{ ( "http://") . (ReadingsVal("mqtt_pc_power","IP",0));; }


and many other variations but i can't get it to append the readings to text... any help appreciated, as usual.

thanks

Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: CoolTux am 01 Oktober 2016, 15:29:31
<html><a href=blabla>Link</a></html>
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: andyclimb am 01 Oktober 2016, 15:44:21
I tried that.  Nothing happens when it is updated.
I need to be able to insert the ReadsVal into a string containing that text.
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: CoolTux am 01 Oktober 2016, 16:00:10
Can you show me a list of device
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: andyclimb am 01 Oktober 2016, 16:20:14
Ok, so i was doing something wrong.  And i've made progress...  but it is not working.  I can inject the IP into the HTML but it is not marking it up in FHEM..  see pictures

Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: CoolTux am 01 Oktober 2016, 16:31:13
And the attr userReading Code?
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: andyclimb am 01 Oktober 2016, 16:36:14

attr mqtt_pc_power  userReadings URL { "<html><a href='http://".( ReadingsVal("mqtt_pc_power","IP",0))."' target='_blank'>Link</a></html>";; }
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: rudolfkoenig am 01 Oktober 2016, 18:12:12
I'm afraid there is extra code (FW_htmlEscape) in 01_FHEMWEB.pm wich is converting html into text.
The <html>bla</html> trick is only used for return values of a command (e.g. get or set), which avoids converting.

I have no problems in activating the trick for this purpose (i.e. displaying readings or attributes) too, but I'd like to hear some comments on it from other developers.
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: andyclimb am 01 Oktober 2016, 18:18:21
That would be ace :)
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: CoolTux am 01 Oktober 2016, 18:29:00
Hallo Rudi,

Danke Dir für Deine Antwort. Die Befürchtung mit dem only Works by return hatte ich schon fast, konnte nur nicht testen.


Grüße
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: rudolfkoenig am 01 Oktober 2016, 20:06:24
I've added an exception for Readings only.
Attributes and Internals are not (yet) handled.

Summary:
if the value of a reading is enclosed in <html>...</html>, then the ... is not escaped, and is sent to the Browser as HTML.
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: andyclimb am 01 Oktober 2016, 23:24:20
I've done an update but this does not seem to changed things. Does it take a while or does a release have to be made to get the changes. Thank you very much for adding this feature.

Andrew
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: justme1968 am 01 Oktober 2016, 23:46:59
every morning at about 8'o clock the changes from the prior day are available with the update command.
Titel: Antw:Create a hyperlink with userReadings?
Beitrag von: andyclimb am 02 Oktober 2016, 19:50:10
That works!  I'm happy.  thanks everyone!