How to use %sysname% in Publish command?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
gibbon_
New user
Posts: 9
Joined: 08 Aug 2016, 11:38
Location: Germany

How to use %sysname% in Publish command?

#1 Post by gibbon_ » 08 Aug 2016, 11:53

Hi,

I was wondering how to use the %sysname% or other template variables in the Publish command in rules. It would be useful to reuse rules on several devices without having to replace stuff.

I tried the follwing in the Tools->Command section:
use in template:
"Publish /%sysname%/test 1" -> "/%sysname%/test 1"
maybe a relative path?
"Publish test 1" -> no publish
maybe as payload?
"Publish /test/ %sysname%" -> Publish /test/ %sysname%

Using the same commands in the Rules:
seems not to work:
"Publish /%sysname%/test 1" -> No publish
seems to work as expected:
"Publish /test/ %sysname%" -> /test/ WZ_Schrank
seems to do nothing (as before):
"Publish test 1" -> no publish

Any hints about how to use the template placeholders in Publish-Statements is appreciated. This is an awesome tool btw... Thanks a lot.

hamster
Normal user
Posts: 62
Joined: 27 Sep 2015, 21:01
Location: UK

Re: How to use %sysname% in Publish command?

#2 Post by hamster » 09 Aug 2016, 22:08

This is how I got publish to work to domoticz

Code: Select all

on Landing_PIR#Switch=1 do
if [Outside_lux#lux]<4
Publish domoticz/in,{"idx":42,"command":"switchlight","switchcmd":"On"}
timerSet,2,10
endon
On Rules#Timer=2 do
Publish domoticz/in,{"idx":42,"command":"switchlight","switchcmd":"Off"}
endon

gibbon_
New user
Posts: 9
Joined: 08 Aug 2016, 11:38
Location: Germany

Re: How to use %sysname% in Publish command?

#3 Post by gibbon_ » 10 Aug 2016, 10:27

Thanks, but publishing itself works just fine.

I want to template the system name into the topic. The template string seems to work fine in the payload but does not seem to work when used in the topic.

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: How to use %sysname% in Publish command?

#4 Post by Drum » 13 Aug 2016, 23:39

Try looking at how the Template for OpenHabMQTT looks,

gibbon_
New user
Posts: 9
Joined: 08 Aug 2016, 11:38
Location: Germany

Re: How to use %sysname% in Publish command?

#5 Post by gibbon_ » 14 Aug 2016, 00:43

Regarding the Webinterface: I did that. This is where the whole question regarding %sysname% was coming from. I saw it used in the MQTT template in the advanced settings and wondered if I could do something similar from the rules.

I will try looking at the source tomorrow. Maybe that will yield an answer.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: How to use %sysname% in Publish command?

#6 Post by tozett » 14 Aug 2016, 11:38

which firmware/version are you on? latest?

gibbon_
New user
Posts: 9
Joined: 08 Aug 2016, 11:38
Location: Germany

Re: How to use %sysname% in Publish command?

#7 Post by gibbon_ » 14 Aug 2016, 18:31

On that particular ESP I am on a R118 built from git. I can update to a current git snapshot no problem though and try my tests again.

Maybe it is better to rephrase my question: Using the Publish command in Rules - is %sysname% supposed to work in the topic? (it works in the payload)

Martinus

Re: How to use %sysname% in Publish command?

#8 Post by Martinus » 14 Aug 2016, 19:52

gibbon_ wrote:Maybe it is better to rephrase my question: Using the Publish command in Rules - is %sysname% supposed to work in the topic? (it works in the payload)
One of the first steps before processing a rule line is to parse anything like %xxx% and [xxx#yyy]. So %sysname% should be replaced regardless of the actual position in the line before it's processed as an event or command. So it would be designed to work that way. Could be hitting a bug though...

gibbon_
New user
Posts: 9
Joined: 08 Aug 2016, 11:38
Location: Germany

Re: How to use %sysname% in Publish command?

#9 Post by gibbon_ » 14 Aug 2016, 21:28

Thank you for the clarification. I will test some more and in case of any results get back to you here and file a bug report.

Martinus

Re: How to use %sysname% in Publish command?

#10 Post by Martinus » 15 Aug 2016, 16:03

You can check the logging to see if parsing the variables has succeeded.

My demo unit is named: Unit_13
Created this demo rule:

Code: Select all

on demo do
  publish /%sysname%/test 1
endon
Using tools/advanced, provide the 'event demo' command and check the log:

Code: Select all

165712055 : EVENT: demo
165712086 : ACT : publish /Unit_13/test 1
As you can see it has translated the action as expected.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: How to use %sysname% in Publish command?

#11 Post by tozett » 18 Aug 2016, 09:56

sounds like solved?
may the Threadstarter could mark his first post here as SOLVED...
thanks..

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: How to use %sysname% in Publish command?

#12 Post by costo » 18 Aug 2016, 10:33

tozett wrote:sounds like solved?
may the Threadstarter could mark his first post here as SOLVED...
thanks..
Is not this for the TopicStarter himself to decide if his issue is solved ?

thank you.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: How to use %sysname% in Publish command?

#13 Post by tozett » 18 Aug 2016, 11:31

Normally,
But look here how many threads are not marked
(Some other Forums are a Bit more cared)
So it is difficult to See solved or still ipen Problem s
For newbies and others.

It was inteded as a polite help to keep the Forum overwiew easy to See Solutions for already solved Problem s

But youre right. This is not really up to me...
:)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 50 guests