Page 1 of 1

How to use %sysname% in Publish command?

Posted: 08 Aug 2016, 11:53
by gibbon_
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.

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

Posted: 09 Aug 2016, 22:08
by hamster
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

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

Posted: 10 Aug 2016, 10:27
by gibbon_
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.

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

Posted: 13 Aug 2016, 23:39
by Drum
Try looking at how the Template for OpenHabMQTT looks,

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

Posted: 14 Aug 2016, 00:43
by gibbon_
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.

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

Posted: 14 Aug 2016, 11:38
by tozett
which firmware/version are you on? latest?

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

Posted: 14 Aug 2016, 18:31
by gibbon_
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)

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

Posted: 14 Aug 2016, 19:52
by Martinus
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...

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

Posted: 14 Aug 2016, 21:28
by gibbon_
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.

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

Posted: 15 Aug 2016, 16:03
by Martinus
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.

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

Posted: 18 Aug 2016, 09:56
by tozett
sounds like solved?
may the Threadstarter could mark his first post here as SOLVED...
thanks..

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

Posted: 18 Aug 2016, 10:33
by costo
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.

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

Posted: 18 Aug 2016, 11:31
by tozett
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...
:)