Skip to content

Commit 939890c

Browse files
authored
Update Berry-Cookbook.md
Elaborated on code to build MQTT topic string
1 parent b63e552 commit 939890c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/Berry-Cookbook.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,13 @@ This is a Tasmota Berry Script library to greatly simplify the process of exposi
792792

793793
## Build MQTT topic string based on FullTopic configuration
794794

795-
This code bit illustrates how you can create a topic string in the form of the `FullTopic` specification. Details like which `%prefix%` you want and what topic last level are obviously variable.
795+
This code bit illustrates how you can create a topic string in the form of the `FullTopic` specification. Details like which `%prefix%` you want and what topic last level are obviously variable. In a class, creating the variable makes snnse in `init()` to avoid issuing commands every time. Commands prefixed with `_` does avoid MQTT messages, but this feature is not available on older Tasmota version.
796796

797797
```berry
798798
var topic = string.replace(string.replace(
799-
tasmota.cmd('FullTopic',true)['FullTopic'],
800-
'%topic%', tasmota.cmd('Topic',true)['Topic']),
801-
'%prefix%', tasmota.cmd('Prefix',true)['Prefix3'])
799+
tasmota.cmd('_FullTopic',true)['FullTopic'],
800+
'%topic%', tasmota.cmd('_Topic',true)['Topic']),
801+
'%prefix%', tasmota.cmd('_Prefix',true)['Prefix3'])
802802
+ 'SENSOR'
803803
```
804804

0 commit comments

Comments
 (0)