Skip to main content

pyinfra-tasmota

A Pyinfra connector for Tasmota devices.

The connector talks to a Tasmota device over its HTTP API. It reads the device settings once at connect time, compares operation intent against that cache, and sends only the commands that are needed as batched Backlog0 requests.

Install

uv add pyinfra-tasmota

Usage

Inventory:

hosts = ["@tasmota/tasmota.example.org"]

Deploy:

from pyinfra_tasmota.operations import apply, cmnd

cmnd(SetOption114=1, SetOption120=0, Power="toggle")
apply()

cmnd takes any number of commands as keyword arguments. A value is either a single value or a list of values. A list ensures each value in order, which suits commands that carry more than one value, such as Interlock 1,2 and Interlock ON:

cmnd(Interlock=["1,2", "ON"], SetOption114=1)

cmnd compares each desired value with the cache. It reads the current value from the device if the setting is not cached, and records a pending change only if the value differs. Every command is sent by apply, or on disconnect as a safety net.

Command names are matched case-insensitively and resolve the SO alias of SetOption, so SetOption114, setoption114, and so114 are the same command. Boolean values are folded, so a desired 0 matches a device value of OFF, and 1 matches ON.

Non-rebooting commands are flushed as Backlog0 batches, split to stay within Tasmota's limit of 30 commands and decode-config's limit of 320 characters per command line. Reboot-triggering commands are sent on their own.

Comparison

cmnd compares the desired value with the device response. A few commands answer with something other than the desired value, so they are compared through an adapter:

  • TimeSTD and TimeDST take a comma-separated list but answer with a struct, which is flattened for the comparison.
  • Pulsetime<x> compares only its Set field.
  • AdcParam<x> compares comma-separated parameters with the device's list. An extra trailing zero in the response is ignored. For example, 36,10000,10000,3350 matches [36,10000,10000,3350,0]. Nonzero extra parameters and changes to explicit parameters still produce a change.
  • Latitude and Longitude are compared with a small tolerance, because the device stores them as micro-degrees using 32-bit float, which loses the last digit.
  • Template is compared as JSON, ignoring ARCH (device architecture) and CMND (commands to run when activating the template).
  • Password1, Password2, and MqttPassword answer with ***, so their diff is skipped and they are always sent.
  • FullTopic 1 selects the firmware default, %prefix%/%topic%/, which is what the desired value is expanded to before comparison.

Deploy

The package ships a deploy that ensures everything under the tasmota host-data key:

# deploy.py
from pyinfra_tasmota import tasmota

tasmota()
# inventory.py
hosts = (
    ["@tasmota/tasmota.example.org"],
    {
        "tasmota": {
            "SetOption114": 1,
            "Rule1": {"code": "ON clock DO power ENDON", "enabled": True},
        },
    },
)

The key holds a mapping of command name to a value or a list of values. The deploy ensures each command, calls apply, then restarts the device and waits for it to return. The restart argument defaults to True, so the final restart runs even when all settings already match.

Use tasmota(restart=False) to skip the final restart. Settings that trigger a reboot still restart the device during apply.

Rule<x> keys are handled like the rule operation rather than as ordinary commands. The value is the rule text, a list of the text followed by flag payloads (Rule1: [code, "1"]), or a mapping with code and the flags (enabled, once, stop_on_error, append). Their text is sent directly, because it can contain semicolons.

ensure_host_data handles a Template key like the template operation with activate=True, after the other commands. It stores the template, selects it with Module 0, and ensures its CMND commands. A separate Module 0 entry is skipped.

This also works when you call ensure_host_data directly, with either the default tasmota key or a custom host-data key:

from pyinfra_tasmota.operations import apply, ensure_host_data

ensure_host_data(key="device_settings")
apply()

Password commands are sent by default. Call tasmota(send_passwords=False) to leave Password1, Password2, and MqttPassword out of the run.

Reboots

Some commands reboot the device, for example Restart, Module, and Template. The connector sends these commands on their own, after all other commands, and waits for the device to answer again before continuing. A device is considered back once it was seen to drop and is answering, or once its BootCount has advanced.

Reboot-triggering settings are still read and diffed like any other command. Only commands whose bare form acts on the device or reports no value, such as Backlog or Restart, are sent without a read.

If the device does not return within tasmota_reboot_timeout (default 60 seconds), apply or restart reports an error.

To send an explicit restart request at operation execution time, use restart:

from pyinfra_tasmota.operations import restart

restart()  # Sends Restart 1.

restart(code=99) sends Restart 99 instead. The operation calls the connector's apply() method before it sends the restart request. You do not need a separate apply() call. If applying pending commands fails, the restart request is not sent. The operation waits for the device to return, then refreshes the settings cache. It uses the same reboot detection and timeout as other reboot-triggering commands.

Templates

The template operation stores a template and activates it by default:

from pyinfra_tasmota.operations import apply, template

template(
    {
        "NAME": "Custom relay",
        "GPIO": [0, 0, 0, 0, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        "FLAG": 0,
        "BASE": 18,
        "CMND": "SetOption114 1|Power ON",
    }
)
apply()

The value can be a dictionary or a JSON object string. The operation compares and queues Template, then ensures Module 0 to select the template. It also ensures each pipe-separated (|) command in CMND. An optional Backlog prefix is accepted. Commands keep their arguments, including spaces.

CMND is removed from the template sent to the device. Its commands and Module 0 are compared even when the stored template already matches. Commands whose values already match are skipped.

With template(value, activate=False), only the template is stored. The operation neither selects Module 0 nor runs the CMND commands.

All changes use the existing queue and need apply() or disconnect to send them. The connector sends ordinary commands before reboot-triggering commands. Thus ordinary CMND commands run before Template and Module, not after activation. Although CMND uses pipes as separators, the queue uses semicolons for Backlog0 batches. Do not put arguments that contain semicolons in this queue, such as complex rule text. Use rule for those rules.

Shutters

The shutter operation configures a shutter. Shutter support has to be enabled first, and the device restarted for that to take effect, so the operation enables SetOption80, restarts the device, waits for it to return, and only then sends the remaining settings:

from pyinfra_tasmota.operations import apply, shutter

shutter(open_duration=12, close_duration=12, relay=1, button=4)
apply()

It sets Interlock <pair> and Interlock ON first (the shutter mode needs the interlock), then ShutterMode, ShutterRelay<x>, ShutterButton<x> (when given), ShutterOpenDuration<x>, and ShutterCloseDuration<x>. index selects the shutter and defaults to 1. Settings that already match are skipped, and the device is only restarted when shutter support has to be enabled. Tasmota stores the travel durations as tenths of a second, so the durations are rounded to one decimal place before they are sent.

Rules

Rule text contains semicolons, which separate Backlog commands, so it cannot be sent in a batch. The rule operation sends the text as its own request and the flags as ordinary commands:

from pyinfra_tasmota.operations import apply, rule

rule("ON clock#Timer=1 DO Power1 ON ENDON", enabled=True, once=False)
apply()

index selects the rule set and defaults to 1. enabled, once, and stop_on_error set the matching flag when given, and append adds to the set instead of replacing it. The text already has semicolons, so the operation never puts it in a backlog.

Verbosity

The connector follows pyinfra's -v flags:

  • -v reports every command sent to the device.
  • -vv also reports the observed state of each command, and any command skipped because the device already matches the desired value.
  • -vvv also reports internal detail, such as the size of the status cache and how commands are grouped into Backlog0 batches.

Secret values (passwords) are masked as *** in these logs.

Versioning

The package version comes from Git via uv-dynamic-versioning. Tag a release as vX.Y.Z; commits after a tag get a .postN.dev0+<hash> suffix. A checkout with no tags reports 0.0.0.

Connector data

Set these on a host in the inventory:

  • tasmota_friendly_name: an optional human-readable name, used in logs.
  • tasmota_reboot_timeout: seconds to wait for a rebooted device to answer again (default 60).

The connector registers itself with Pyinfra under the name tasmota, so use @tasmota/<host> anywhere a connector is expected.

Metadata

Release files for pyinfra-tasmota 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyinfra-tasmota 0.3.0
File Size Uploaded Provenance Actions
pyinfra_tasmota-0.3.0.tar.gz 201.3 kB With provenance Details for pyinfra_tasmota-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyinfra-tasmota 0.3.0
File Interpreter ABI Platform Actions
pyinfra_tasmota-0.3.0-py3-none-any.whl Python 3 none any Details for pyinfra_tasmota-0.3.0-py3-none-any.whl

Total release size: 223.2 kB

Release files / pyinfra_tasmota-0.3.0.tar.gz

Download URL pyinfra_tasmota-0.3.0.tar.gz
Size 201.3 kB
Tags Source
SHA-256 checksum
How to use checksums
88db7433460eb2b30b0728bc25d3c887bd147aed945dd27a7172b58f954e5c97
BLAKE2b-256 checksum
How to use checksums
fbb53ff1024c702e1c18adbfcd6c1b8ec213e129b8f37601f58dc0fa47d9c40d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / pyinfra_tasmota-0.3.0-py3-none-any.whl

Download URL pyinfra_tasmota-0.3.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfa40cc6e21fdd20aee8040ba017ce29c10a3aa0108c10ebf9a70c3956013cfd
BLAKE2b-256 checksum
How to use checksums
7b646838703f32f27cf7d18576009f83eca755b6ef1950fb5cad6621221581ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for pyinfra-tasmota 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyinfra_tasmota-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page