decode-config.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <h1 id="decode-config-py">decode-config.py</h1>
  2. <p><em>decode-config.py</em> is able to backup and restore Sonoff-Tasmota configuration.</p>
  3. <p>In contrast to the Tasmota build-in &quot;Backup/Restore Configuration&quot; function,</p>
  4. <ul>
  5. <li><em>decode-config.py</em> uses human readable and editable <a href="http://www.json.org/">JSON</a>-format for backup/restore,</li>
  6. <li><em>decode-config.py</em> can restore previous backuped and changed <a href="http://www.json.org/">JSON</a>-format files,</li>
  7. <li><em>decode-config.py</em> is able to create Tasmota commands based on given configuration</li>
  8. </ul>
  9. <p>Comparing backup files created by <em>decode-config.py</em> and *.dmp files created by Tasmota &quot;Backup/Restore Configuration&quot;: </p>
  10. <table>
  11. <thead>
  12. <tr>
  13. <th>&nbsp;</th>
  14. <th style="text-align:center">decode-config.py<br />*.json file</th>
  15. <th style="text-align:center">Sonoff-Tasmota<br />*.dmp file</th>
  16. </tr>
  17. </thead>
  18. <tbody>
  19. <tr>
  20. <td>Encrypted</td>
  21. <td style="text-align:center">No</td>
  22. <td style="text-align:center">Yes</td>
  23. </tr>
  24. <tr>
  25. <td>Readable</td>
  26. <td style="text-align:center">Yes</td>
  27. <td style="text-align:center">No</td>
  28. </tr>
  29. <tr>
  30. <td>Simply editable</td>
  31. <td style="text-align:center">Yes</td>
  32. <td style="text-align:center">No</td>
  33. </tr>
  34. <tr>
  35. <td>Simply batch processing</td>
  36. <td style="text-align:center">Yes</td>
  37. <td style="text-align:center">No</td>
  38. </tr>
  39. </tbody>
  40. </table>
  41. <p><em>decode-config.py</em> is able to handle Tasmota configurations for release version starting from 5.10.0 up to now.</p>
  42. <h1 id="content">Content</h1>
  43. <ul>
  44. <li><a href="decode-config.md#prerequisite">Prerequisite</a></li>
  45. <li><a href="decode-config.md#file-types">File Types</a><ul>
  46. <li><a href="decode-config.md#-dmp-format">.dmp File Format</a></li>
  47. <li><a href="decode-config.md#-json-format">.json File Format</a></li>
  48. <li><a href="decode-config.md#-bin-format">.bin File Format</a><ul>
  49. <li><a href="decode-config.md#file-extensions">File extensions</a></li>
  50. </ul>
  51. </li>
  52. </ul>
  53. </li>
  54. <li><a href="decode-config.md#usage">Usage</a><ul>
  55. <li><a href="decode-config.md#basics">Basics</a></li>
  56. <li><a href="decode-config.md#save-backup-file">Save backup file</a></li>
  57. <li><a href="decode-config.md#restore-backup-file">Restore backup file</a></li>
  58. <li><a href="decode-config.md#output-to-screen">Output to screen</a><ul>
  59. <li><a href="decode-config.md#json-output">JSON output</a></li>
  60. <li><a href="decode-config.md#tasmota-command-output">Tasmota command output</a></li>
  61. </ul>
  62. </li>
  63. <li><a href="decode-config.md#filter-data">Filter data</a></li>
  64. <li><a href="decode-config.md#configuration-file">Configuration file</a></li>
  65. <li><a href="decode-config.md#more-program-arguments">More program arguments</a></li>
  66. <li><a href="decode-config.md#examples">Examples</a><ul>
  67. <li><a href="decode-config.md#config-file">Config file</a></li>
  68. <li><a href="decode-config.md#using-tasmota-binary-configuration-files">Using Tasmota binary configuration files</a></li>
  69. <li><a href="decode-config.md#use-batch-processing">Use batch processing</a></li>
  70. </ul>
  71. </li>
  72. <li><a href="decode-config.md#notes">Notes</a></li>
  73. </ul>
  74. </li>
  75. </ul>
  76. <h2 id="prerequisite">Prerequisite</h2>
  77. <ul>
  78. <li><p><a href="https://en.wikipedia.org/wiki/Python_(programming_language">Python</a>)<br>This program is written in <a href="https://en.wikipedia.org/wiki/Python_(programming_language">Python</a>) so you need to install a python environment (for details see <a href="https://docs.python.org/2.7/using/index.html">Python Setup and Usage</a>)</p>
  79. </li>
  80. <li><p><a href="https://github.com/arendst/Sonoff-Tasmota">Sonoff-Tasmota</a> <a href="https://github.com/arendst/Sonoff-Tasmota/releases">Firmware</a> with Web-Server enabled:</p>
  81. <ul>
  82. <li>To backup or restore configurations from/to a Sonoff-Tasmota device you need a firmare with enabled web-server in admin mode (command <a href="https://github.com/arendst/Sonoff-Tasmota/wiki/Commands#wifi">WebServer 2</a>).</li>
  83. <li>If using your own compiled firmware be aware to enable the web-server (<code>#define USE_WEBSERVER</code> and <code>#define WEB_SERVER 2</code>).</li>
  84. </ul>
  85. </li>
  86. </ul>
  87. <h2 id="file-types">File Types</h2>
  88. <p><em>decode-config.py</em> can handle the following backup file types: </p>
  89. <h3 id="-dmp-format">.dmp Format</h3>
  90. <p>Configuration data as used by Tasmota &quot;Backup/Restore Configuration&quot; web interface.<br>This format is binary and encrypted.</p>
  91. <h3 id="-json-format">.json Format</h3>
  92. <p>Configuration data in <a href="http://www.json.org/">JSON</a>-format.<br>This format is decrypted, human readable and editable and can also be used for the <code>--restore-file</code> command.<br>This file will becreated by <em>decode-config.py</em> using <code>--backup-file</code> with <code>--backup-type json</code> parameter (default).</p>
  93. <h3 id="-bin-format">.bin Format</h3>
  94. <p>Configuration data in binary format.<br>This format is binary decryptet, editable (e.g. using a hex editor) and can also be used for <code>--restore-file</code> command.<br>It will be created by <em>decode-config.py</em> using <code>--backup-file</code> with <code>--backup-type bin</code>.<br>Note:<br>This file is 4 byte longer than an original .dmp file due to an prefix header at the beginning. The file data starting at address position 4 are containing the same as the <strong>struct SYSCFG</strong> from Tasmota <a href="https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/settings.h">settings.h</a> in decrypted format.</p>
  95. <h4 id="file-extensions">File extensions</h4>
  96. <p><em>decode-config.py</em> uses auto extension as default for backup filenames; you don&#39;t need to append extensions to your backup file, it will be selected based on <code>--backup-type</code> argument.<br>If you want using your own extension use the <code>--no-extension</code> argument.</p>
  97. <h2 id="usage">Usage</h2>
  98. <p>After download don&#39;t forget to set exec flag under linux with <code>chmod +x decode-config.py</code> or call the program using <code>python decode-config.py...</code>.</p>
  99. <h3 id="basics">Basics</h3>
  100. <p>At least pass a source where you want to read the configuration data from using <code>-f &lt;filename&gt;</code> or <code>-d &lt;host&gt;</code>:</p>
  101. <p>The source can be either </p>
  102. <ul>
  103. <li>a Tasmota device hostname or IP by passing it using the <code>-d &lt;host&gt;</code> arg</li>
  104. <li>or a previously stored Tasmota <code>*.dmp</code> configuration file by passing the filename using <code>-f &lt;filename&gt;</code> arg</li>
  105. </ul>
  106. <p>Example: </p>
  107. <pre><code>decode-config<span class="hljs-selector-class">.py</span> -d sonoff-<span class="hljs-number">4281</span>
  108. </code></pre><p>will output a human readable configuration in <a href="http://www.json.org/">JSON</a>-format:</p>
  109. <pre><code>{
  110. <span class="hljs-string">"altitude"</span>: <span class="hljs-number">112</span>,
  111. <span class="hljs-string">"baudrate"</span>: <span class="hljs-number">115200</span>,
  112. <span class="hljs-string">"blinkcount"</span>: <span class="hljs-number">10</span>,
  113. <span class="hljs-string">"blinktime"</span>: <span class="hljs-number">10</span>,
  114. ...
  115. <span class="hljs-string">"ws_width"</span>: [
  116. <span class="hljs-number">1</span>,
  117. <span class="hljs-number">3</span>,
  118. <span class="hljs-number">5</span>
  119. ]
  120. }
  121. </code></pre><h3 id="save-backup-file">Save backup file</h3>
  122. <p>To save the output as backup file <code>--backup-file &lt;filename&gt;</code>, you can use placeholder for Version, Friendlyname and Hostname: </p>
  123. <pre><code><span class="hljs-selector-tag">decode-config</span><span class="hljs-selector-class">.py</span> <span class="hljs-selector-tag">-d</span> <span class="hljs-selector-tag">sonoff-4281</span> <span class="hljs-selector-tag">--backup-file</span> <span class="hljs-selector-tag">Config_</span>@<span class="hljs-keyword">f_</span>@<span class="hljs-keyword">v</span>
  124. </code></pre><p>If you have setup a WebPassword within Tasmota, use</p>
  125. <pre><code>decode-config<span class="hljs-selector-class">.py</span> -d sonoff-<span class="hljs-number">4281</span> -<span class="hljs-selector-tag">p</span> &lt;yourpassword&gt; --backup-file Config_@f_@v
  126. </code></pre><p>will create a file like <code>Config_Sonoff_x.x.x.json</code>. Because it is in JSON format, you can read and edit the file with any raw text editor.</p>
  127. <h3 id="restore-backup-file">Restore backup file</h3>
  128. <p>Reading back a saved (and possible changed) backup file use the <code>--restore-file &lt;filename&gt;</code> arg. This will read the (changed) configuration data from this file and send it back to the source device or filename.</p>
  129. <p>To restore the previously save backup file <code>Config_Sonoff_6.2.1.json</code> to device <code>sonoff-4281</code> use: </p>
  130. <pre><code><span class="hljs-selector-tag">decode-config</span><span class="hljs-selector-class">.py</span> <span class="hljs-selector-tag">-d</span> <span class="hljs-selector-tag">sonoff-4281</span> <span class="hljs-selector-tag">--restore-file</span> <span class="hljs-selector-tag">Config_Sonoff_6</span><span class="hljs-selector-class">.2</span><span class="hljs-selector-class">.1</span><span class="hljs-selector-class">.json</span>
  131. </code></pre><p>with password set by WebPassword:</p>
  132. <pre><code><span class="hljs-selector-tag">decode-config</span><span class="hljs-selector-class">.py</span> <span class="hljs-selector-tag">-d</span> <span class="hljs-selector-tag">sonoff-4281</span> <span class="hljs-selector-tag">-p</span> &lt;<span class="hljs-selector-tag">yourpassword</span>&gt; <span class="hljs-selector-tag">--restore-file</span> <span class="hljs-selector-tag">Config_Sonoff_6</span><span class="hljs-selector-class">.2</span><span class="hljs-selector-class">.1</span><span class="hljs-selector-class">.json</span>
  133. </code></pre><h3 id="output-to-screen">Output to screen</h3>
  134. <p>Output to screen is default enabled when calling the program with a source arg but without a backup or restore arg.</p>
  135. <p><code>--output</code> arg will force screen output even if you use backup or restore arg.</p>
  136. <h4 id="json-output">JSON output</h4>
  137. <p>The default output format is JSON. You can force JSON output with <code>--output-format json</code> arg.</p>
  138. <p>Example:</p>
  139. <pre><code>decode-config.py -d sonoff<span class="hljs-number">-4281</span> -c my.conf -x <span class="hljs-symbol">Wifi</span> --output-format json
  140. {
  141. ...
  142. <span class="hljs-string">"hostname"</span>: <span class="hljs-string">"%s-%04d"</span>,
  143. <span class="hljs-string">"ip_address"</span>: [
  144. <span class="hljs-string">"0.0.0.0"</span>,
  145. <span class="hljs-string">"192.168.12.1"</span>,
  146. <span class="hljs-string">"255.255.255.0"</span>,
  147. <span class="hljs-string">"192.168.12.1"</span>
  148. ],
  149. <span class="hljs-string">"ntp_server"</span>: [
  150. <span class="hljs-string">"ntp.localnet.home"</span>,
  151. <span class="hljs-string">"ntp2.localnet.home"</span>,
  152. <span class="hljs-string">"192.168.12.1"</span>
  153. ],
  154. <span class="hljs-string">"sta_active"</span>: <span class="hljs-number">0</span>,
  155. <span class="hljs-string">"sta_config"</span>: <span class="hljs-number">5</span>,
  156. <span class="hljs-string">"sta_pwd"</span>: [
  157. <span class="hljs-string">"myWlAnPaszxwo!z"</span>,
  158. <span class="hljs-string">"myWlAnPaszxwo!z2"</span>
  159. ],
  160. <span class="hljs-string">"sta_ssid"</span>: [
  161. <span class="hljs-string">"wlan.1"</span>,
  162. <span class="hljs-string">"my-wlan"</span>
  163. ],
  164. <span class="hljs-string">"web_password"</span>: <span class="hljs-string">"myPaszxwo!z"</span>,
  165. <span class="hljs-string">"webserver"</span>: <span class="hljs-number">2</span>
  166. ...
  167. }
  168. </code></pre><p>Note: JSON output always contains all configuration data like the backup file except you are using <code>--group</code> arg.</p>
  169. <h4 id="tasmota-command-output">Tasmota command output</h4>
  170. <p><em>decode-config.py</em> is able to translate the configuration data to (most all) Tasmota commands. To output your configuration as Tasmota commands use <code>--output-format cmnd</code> or <code>--output-format command</code>.</p>
  171. <p>Example:</p>
  172. <pre><code><span class="hljs-selector-tag">decode-config</span><span class="hljs-selector-class">.py</span> <span class="hljs-selector-tag">-d</span> <span class="hljs-selector-tag">sonoff-4281</span> <span class="hljs-selector-tag">-c</span> <span class="hljs-selector-tag">my</span><span class="hljs-selector-class">.conf</span> <span class="hljs-selector-tag">-g</span> <span class="hljs-selector-tag">Wifi</span> <span class="hljs-selector-tag">--output-format</span> <span class="hljs-selector-tag">cmnd</span>
  173. # <span class="hljs-selector-tag">Wifi</span>:
  174. <span class="hljs-selector-tag">AP</span> 0
  175. <span class="hljs-selector-tag">Hostname</span> %<span class="hljs-selector-tag">s-</span>%04<span class="hljs-selector-tag">d</span>
  176. <span class="hljs-selector-tag">IPAddress1</span> 0<span class="hljs-selector-class">.0</span><span class="hljs-selector-class">.0</span><span class="hljs-selector-class">.0</span>
  177. <span class="hljs-selector-tag">IPAddress2</span> 192<span class="hljs-selector-class">.168</span><span class="hljs-selector-class">.12</span><span class="hljs-selector-class">.1</span>
  178. <span class="hljs-selector-tag">IPAddress3</span> 255<span class="hljs-selector-class">.255</span><span class="hljs-selector-class">.255</span><span class="hljs-selector-class">.0</span>
  179. <span class="hljs-selector-tag">IPAddress4</span> 192<span class="hljs-selector-class">.168</span><span class="hljs-selector-class">.12</span><span class="hljs-selector-class">.1</span>
  180. <span class="hljs-selector-tag">NtpServer1</span> <span class="hljs-selector-tag">ntp</span><span class="hljs-selector-class">.localnet</span><span class="hljs-selector-class">.home</span>
  181. <span class="hljs-selector-tag">NtpServer2</span> <span class="hljs-selector-tag">ntp2</span><span class="hljs-selector-class">.localnet</span><span class="hljs-selector-class">.home</span>
  182. <span class="hljs-selector-tag">NtpServer3</span> 192<span class="hljs-selector-class">.168</span><span class="hljs-selector-class">.12</span><span class="hljs-selector-class">.1</span>
  183. <span class="hljs-selector-tag">Password1</span> <span class="hljs-selector-tag">myWlAnPaszxwo</span>!<span class="hljs-selector-tag">z</span>
  184. <span class="hljs-selector-tag">Password2</span> <span class="hljs-selector-tag">myWlAnPaszxwo</span>!<span class="hljs-selector-tag">z2</span>
  185. <span class="hljs-selector-tag">SSId1</span> <span class="hljs-selector-tag">wlan</span><span class="hljs-selector-class">.1</span>
  186. <span class="hljs-selector-tag">SSId2</span> <span class="hljs-selector-tag">wlan</span><span class="hljs-selector-class">.1</span>
  187. <span class="hljs-selector-tag">WebPassword</span> <span class="hljs-selector-tag">myPaszxwo</span>!<span class="hljs-selector-tag">z</span>
  188. <span class="hljs-selector-tag">WebServer</span> 2
  189. <span class="hljs-selector-tag">WifiConfig</span> 5
  190. </code></pre><p>Note: A few very specific module commands like MPC230xx, KNX and some Display commands are not supported. These are still available by JSON output.</p>
  191. <h3 id="filter-data">Filter data</h3>
  192. <p>The huge number of Tasmota configuration data can be overstrained and confusing, so the most of the configuration data are grouped into categories. </p>
  193. <p>With <em>decode-config.py</em> the following categories are available: <code>Display</code>, <code>Domoticz</code>, <code>Internal</code>, <code>KNX</code>, <code>Led</code>, <code>Logging</code>, <code>MCP230xx</code>, <code>MQTT</code>, <code>Main</code>, <code>Management</code>, <code>Pow</code>, <code>Sensor</code>, <code>Serial</code>, <code>SetOption</code>, <code>SonoffRF</code>, <code>System</code>, <code>Timers</code>, <code>Wifi</code></p>
  194. <p>These are similary to the categories on <a href="Tasmota Command Wiki">https://github.com/arendst/Sonoff-Tasmota/wiki/Commands</a>.</p>
  195. <p>To filter outputs to a subset of groups use the <code>-g</code> or <code>--group</code> arg concatenating the grooup you want, e. g.</p>
  196. <pre><code>decode-config<span class="hljs-selector-class">.py</span> -d sonoff-<span class="hljs-number">4281</span> -c my<span class="hljs-selector-class">.conf</span> --output-format cmnd --group Main MQTT Management Wifi
  197. </code></pre><h3 id="configuration-file">Configuration file</h3>
  198. <p>Each argument that start with <code>--</code> (eg. <code>--file</code>) can also be set in a config file (specified via -c). Config file syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at <a href="https://pypi.org/project/ConfigArgParse/">https://pypi.org/project/ConfigArgParse</a>).</p>
  199. <p>If an argument is specified in more than one place, then commandline values override config file values which override defaults. This is usefull if you always use the same argument or a basic set of arguments.</p>
  200. <p>The http authentication credentials <code>--username</code> and <code>--password</code> is predestinated to store it in a file instead using it on your command line as argument:</p>
  201. <p>e.g. my.conf:</p>
  202. <pre><code><span class="hljs-section">[source]</span>
  203. <span class="hljs-attr">username</span> = admin
  204. <span class="hljs-attr">password</span> = myPaszxwo!z
  205. </code></pre><p>To make a backup file from example above you can now pass the config file instead using the password on command line:</p>
  206. <pre><code><span class="hljs-selector-tag">decode-config</span><span class="hljs-selector-class">.py</span> <span class="hljs-selector-tag">-d</span> <span class="hljs-selector-tag">sonoff-4281</span> <span class="hljs-selector-tag">-c</span> <span class="hljs-selector-tag">my</span><span class="hljs-selector-class">.conf</span> <span class="hljs-selector-tag">--backup-file</span> <span class="hljs-selector-tag">Config_</span>@<span class="hljs-keyword">f_</span>@<span class="hljs-keyword">v</span>
  207. </code></pre><h3 id="more-program-arguments">More program arguments</h3>
  208. <p>For better reading each short written arg (minus sign <code>-</code>) has a corresponding long version (two minus signs <code>--</code>), eg. <code>--device</code> for <code>-d</code> or <code>--file</code> for <code>-f</code> (note: not even all <code>--</code> arg has a corresponding <code>-</code> one).</p>
  209. <p>A short list of possible program args is displayed using <code>-h</code> or <code>--help</code>.</p>
  210. <p>For advanced help use <code>-H</code> or <code>--full-help</code>:</p>
  211. <pre><code><span class="hljs-title">usage</span>: decode-config.py [-f &lt;filename&gt;] [-d &lt;host&gt;] [-<span class="hljs-type">P</span> &lt;port&gt;]
  212. [-u &lt;username&gt;] [-p &lt;password&gt;] [-i &lt;filename&gt;]
  213. [-o &lt;filename&gt;] [-t json|bin|dmp] [-<span class="hljs-type">E</span>] [-e] [-<span class="hljs-type">F</span>]
  214. [<span class="hljs-comment">--json-indent &lt;indent&gt;] [--json-compact]</span>
  215. [<span class="hljs-comment">--json-hide-pw] [--json-show-pw]</span>
  216. [<span class="hljs-comment">--cmnd-indent &lt;indent&gt;] [--cmnd-groups]</span>
  217. [<span class="hljs-comment">--cmnd-nogroups] [--cmnd-sort] [--cmnd-unsort]</span>
  218. [-c &lt;filename&gt;] [-<span class="hljs-type">S</span>] [-<span class="hljs-type">T</span> json|cmnd|command]
  219. [-g {<span class="hljs-type">Display</span>,<span class="hljs-type">Domoticz</span>,<span class="hljs-type">Internal</span>,<span class="hljs-type">KNX</span>,<span class="hljs-type">Led</span>,<span class="hljs-type">Logging</span>,<span class="hljs-type">MCP230xx</span>,<span class="hljs-type">MQTT</span>,<span class="hljs-type">Main</span>,<span class="hljs-type">Management</span>,<span class="hljs-type">Pow</span>,<span class="hljs-type">Sensor</span>,<span class="hljs-type">Serial</span>,<span class="hljs-type">SetOption</span>,<span class="hljs-type">SonoffRF</span>,<span class="hljs-type">System</span>,<span class="hljs-type">Timers</span>,<span class="hljs-type">Wifi</span>} [{<span class="hljs-type">Display</span>,<span class="hljs-type">Domoticz</span>,<span class="hljs-type">Internal</span>,<span class="hljs-type">KNX</span>,<span class="hljs-type">Led</span>,<span class="hljs-type">Logging</span>,<span class="hljs-type">MCP230xx</span>,<span class="hljs-type">MQTT</span>,<span class="hljs-type">Main</span>,<span class="hljs-type">Management</span>,<span class="hljs-type">Pow</span>,<span class="hljs-type">Sensor</span>,<span class="hljs-type">Serial</span>,<span class="hljs-type">SetOption</span>,<span class="hljs-type">SonoffRF</span>,<span class="hljs-type">System</span>,<span class="hljs-type">Timers</span>,<span class="hljs-type">Wifi</span>} ...]]
  220. [<span class="hljs-comment">--ignore-warnings] [-h] [-H] [-v] [-V]</span>
  221. <span class="hljs-type">Backup</span>/<span class="hljs-type">Restore</span> <span class="hljs-type">Sonoff</span>-<span class="hljs-type">Tasmota</span> configuration <span class="hljs-class"><span class="hljs-keyword">data</span>. <span class="hljs-type">Args</span> that start with '<span class="hljs-comment">--'</span></span>
  222. (eg. -f) can also be set <span class="hljs-keyword">in</span> a config file (specified via -c). <span class="hljs-type">Config</span> file
  223. <span class="hljs-title">syntax</span> allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at
  224. <span class="hljs-title">https</span>://goo.gl/<span class="hljs-type">R74nmi</span>). <span class="hljs-type">If</span> an arg is specified <span class="hljs-keyword">in</span> more than one place, <span class="hljs-keyword">then</span>
  225. <span class="hljs-title">commandline</span> values override config file values which override defaults.
  226. <span class="hljs-type">Source</span>:
  227. <span class="hljs-type">Read</span>/<span class="hljs-type">Write</span> <span class="hljs-type">Tasmota</span> configuration from/to
  228. -f, <span class="hljs-comment">--file, --tasmota-file &lt;filename&gt;</span>
  229. file to retrieve/write <span class="hljs-type">Tasmota</span> configuration from/to
  230. (<span class="hljs-keyword">default</span>: <span class="hljs-type">None</span>)'
  231. -d, <span class="hljs-comment">--device, --host &lt;host&gt;</span>
  232. hostname or <span class="hljs-type">IP</span> address to retrieve/send <span class="hljs-type">Tasmota</span>
  233. configuration from/to (<span class="hljs-keyword">default</span>: <span class="hljs-type">None</span>)
  234. -<span class="hljs-type">P</span>, <span class="hljs-comment">--port &lt;port&gt; TCP/IP port number to use for the host connection</span>
  235. (<span class="hljs-keyword">default</span>: 80)
  236. -u, <span class="hljs-comment">--username &lt;username&gt;</span>
  237. host <span class="hljs-type">HTTP</span> access username (<span class="hljs-keyword">default</span>: admin)
  238. -p, <span class="hljs-comment">--password &lt;password&gt;</span>
  239. host <span class="hljs-type">HTTP</span> access password (<span class="hljs-keyword">default</span>: <span class="hljs-type">None</span>)
  240. <span class="hljs-type">Backup</span>/<span class="hljs-type">Restore</span>:
  241. <span class="hljs-type">Backup</span> &amp; restore specification
  242. -i, <span class="hljs-comment">--restore-file &lt;filename&gt;</span>
  243. file to restore configuration from (<span class="hljs-keyword">default</span>: <span class="hljs-type">None</span>).
  244. <span class="hljs-type">Replacements</span>: @v=firmware version from config,
  245. @f=device friendly name from config, @h=device
  246. hostname from config, @<span class="hljs-type">H</span>=device hostname from device
  247. (-d arg only)
  248. -o, <span class="hljs-comment">--backup-file &lt;filename&gt;</span>
  249. file to backup configuration to (<span class="hljs-keyword">default</span>: <span class="hljs-type">None</span>).
  250. <span class="hljs-type">Replacements</span>: @v=firmware version from config,
  251. @f=device friendly name from config, @h=device
  252. hostname from config, @<span class="hljs-type">H</span>=device hostname from device
  253. (-d arg only)
  254. -t, <span class="hljs-comment">--backup-type json|bin|dmp</span>
  255. backup filetype (<span class="hljs-keyword">default</span>: 'json')
  256. -<span class="hljs-type">E</span>, <span class="hljs-comment">--extension append filetype extension for -i and -o filename</span>
  257. (<span class="hljs-keyword">default</span>)
  258. -e, <span class="hljs-comment">--no-extension do not append filetype extension, use -i and -o</span>
  259. filename <span class="hljs-keyword">as</span> passed
  260. -<span class="hljs-type">F</span>, <span class="hljs-comment">--force-restore force restore even configuration is identical</span>
  261. <span class="hljs-type">JSON</span> output:
  262. <span class="hljs-type">JSON</span> format specification
  263. <span class="hljs-comment">--json-indent &lt;indent&gt;</span>
  264. pretty-printed <span class="hljs-type">JSON</span> output using indent level
  265. (<span class="hljs-keyword">default</span>: '<span class="hljs-type">None'</span>). -1 disables indent.
  266. <span class="hljs-comment">--json-compact compact JSON output by eliminate whitespace</span>
  267. <span class="hljs-comment">--json-hide-pw hide passwords</span>
  268. <span class="hljs-comment">--json-show-pw, --json-unhide-pw</span>
  269. unhide passwords (<span class="hljs-keyword">default</span>)
  270. <span class="hljs-type">Tasmota</span> command output:
  271. <span class="hljs-type">Tasmota</span> command output format specification
  272. <span class="hljs-comment">--cmnd-indent &lt;indent&gt;</span>
  273. <span class="hljs-type">Tasmota</span> command grouping indent level (<span class="hljs-keyword">default</span>: '2').
  274. <span class="hljs-number">0</span> disables indent
  275. <span class="hljs-comment">--cmnd-groups group Tasmota commands (default)</span>
  276. <span class="hljs-comment">--cmnd-nogroups leave Tasmota commands ungrouped</span>
  277. <span class="hljs-comment">--cmnd-sort sort Tasmota commands (default)</span>
  278. <span class="hljs-comment">--cmnd-unsort leave Tasmota commands unsorted</span>
  279. <span class="hljs-type">Common</span>:
  280. <span class="hljs-type">Optional</span> arguments
  281. -c, <span class="hljs-comment">--config &lt;filename&gt;</span>
  282. program config file - can be used to set <span class="hljs-keyword">default</span>
  283. command args (<span class="hljs-keyword">default</span>: <span class="hljs-type">None</span>)
  284. -<span class="hljs-type">S</span>, <span class="hljs-comment">--output display output regardsless of backup/restore usage</span>
  285. (<span class="hljs-keyword">default</span> do not output on backup or restore usage)
  286. -<span class="hljs-type">T</span>, <span class="hljs-comment">--output-format json|cmnd|command</span>
  287. display output format (<span class="hljs-keyword">default</span>: 'json')
  288. -g, <span class="hljs-comment">--group {Display,Domoticz,Internal,KNX,Led,Logging,MCP230xx,MQTT,Main,Management,Pow,Sensor,Serial,SetOption,SonoffRF,System,Timers,Wifi}</span>
  289. limit <span class="hljs-class"><span class="hljs-keyword">data</span> processing to command groups (<span class="hljs-title">default</span> <span class="hljs-title">no</span>
  290. <span class="hljs-title">filter</span>)</span>
  291. <span class="hljs-comment">--ignore-warnings do not exit on warnings. Not recommended, used by your</span>
  292. own responsibility!
  293. <span class="hljs-type">Info</span>:
  294. <span class="hljs-type">Extra</span> information
  295. -h, <span class="hljs-comment">--help show usage help message and exit</span>
  296. -<span class="hljs-type">H</span>, <span class="hljs-comment">--full-help show full help message and exit</span>
  297. -v, <span class="hljs-comment">--verbose produce more output about what the program does</span>
  298. -<span class="hljs-type">V</span>, <span class="hljs-comment">--version show program's version number and exit</span>
  299. <span class="hljs-type">Either</span> argument -d &lt;host&gt; or -f &lt;filename&gt; must be given.
  300. </code></pre><h3 id="program-parameter-notes">Program parameter notes</h3>
  301. <p><em>decode-config.py</em></p>
  302. <h3 id="examples">Examples</h3>
  303. <p>The most of the examples are for linux command line. Under Windows call the program using <code>python decode-config.py ...</code>.</p>
  304. <h4 id="config-file">Config file</h4>
  305. <p>Note: The example contains .ini style sections <code>[...]</code>. Sections are always treated as comment and serves as clarity only.
  306. For further details of config file syntax see <a href="https://pypi.org/project/ConfigArgParse/">https://pypi.org/project/ConfigArgParse</a>.</p>
  307. <p><em>my.conf</em></p>
  308. <pre><code><span class="hljs-string">[Source]</span>
  309. username = admin
  310. password = myPaszxwo!z
  311. <span class="hljs-string">[JSON]</span>
  312. json-indent <span class="hljs-number">2</span>
  313. </code></pre><h4 id="using-tasmota-binary-configuration-files">Using Tasmota binary configuration files</h4>
  314. <ol>
  315. <li><p>Restore a Tasmota configuration file</p>
  316. <p> <code>decode-config.py -c my.conf -d sonoff --restore-file Config_Sonoff_6.2.1.dmp</code></p>
  317. </li>
  318. <li><p>Backup device using Tasmota configuration compatible format</p>
  319. <p>a) use file extension to choice the file format</p>
  320. <p> <code>decode-config.py -c my.conf -d sonoff --backup-file Config_@f_@v.dmp</code></p>
  321. <p>b) use args to choice the file format</p>
  322. <p> <code>decode-config.py -c my.conf -d sonoff --backup-type dmp --backup-file Config_@f_@v</code></p>
  323. </li>
  324. </ol>
  325. <h4 id="use-batch-processing">Use batch processing</h4>
  326. <pre><code><span class="hljs-keyword">for</span> device <span class="hljs-keyword">in</span> sonoff1 sonoff2 sonoff3; <span class="hljs-keyword">do</span> ./decode-config.py -c my.conf -d <span class="hljs-variable">$device</span> -o Config<span class="hljs-number">_</span><span class="hljs-variable">@f_</span><span class="hljs-variable">@v</span>
  327. </code></pre><p>or under windows</p>
  328. <pre><code><span class="hljs-keyword">for</span> device <span class="hljs-keyword">in</span> (sonoff1 sonoff2 sonoff3) <span class="hljs-keyword">do</span> <span class="hljs-keyword">python</span> decode-config.py -c my.conf -d %device -o Config_@f_@v
  329. </code></pre><p>will produce JSON configuration files for host sonoff1, sonoff2 and sonoff3 using friendly name and Tasmota firmware version for backup filenames.</p>
  330. <h2 id="notes">Notes</h2>
  331. <p>Some general notes:</p>
  332. <ul>
  333. <li>Filename replacement macros <strong>@h</strong> and <strong>@H</strong>:<ul>
  334. <li><strong>@h</strong><br>The <strong>@h</strong> replacement macro uses the hostname configured with the Tasomta Wifi <code>Hostname &lt;host&gt;</code> command (defaults to <code>%s-%04d</code>). It will not use the network hostname of your device because this is not available when working with files only (e.g. <code>--file &lt;filename&gt;</code> as source).<br>To prevent having a useless % in your filename, <strong>@h</strong> will not replaced by configuration data hostname if this contains &#39;%&#39; characters.</li>
  335. <li><strong>@H</strong><br>If you want to use the network hostname within your filename, use the <strong>@H</strong> replacement macro instead - but be aware this will only replaced if you are using a network device as source (<code>-d</code>, <code>--device</code>, <code>--host</code>); it will not work when using a file as source (<code>-f</code>, <code>--file</code>)</li>
  336. </ul>
  337. </li>
  338. </ul>