tobias_richter.tasmota
tobias_richter.tasmota
This role helps you configure Tasmota devices by running commands.
:bulb: For a list of commands, check https://tasmota.github.io/docs/#/Commands.
This role will send commands to a Tasmota device using web requests. For each command
and value
pair in tasmota_commands
, it will:
- Get the current setting of the specified
command
. - Compare it with the new
value
.- If the new value is different, it will run the command and mark the task as
changed
. - If there’s no change, it won’t run the command, preventing unnecessary restarts.
- If the new value is different, it will run the command and mark the task as
Requirements
Install the necessary Python packages by running:
pip install -r requirements.txt
Limitations
Fact Gathering
Disable fact gathering by using gather_facts: no
, because Tasmota devices don't work with the facts module right now.
changed
Reporting
Some commands, like SetOption
, take integer values (like 0
or 1
) but return on
or off
when you check the status. This can lead to incorrect "changed" reports. Feel free to suggest improvements for unsupported commands.
Role Variables
Here are the available variables and their default values:
tasmota_user: ''
tasmota_password: ''
tasmota_commands: []
tasmota_mqtt_user: ''
tasmota_mqtt_password: ''
tasmota_mqtt_host: ''
tasmota_mqtt_port: ''
tasmota_mqtt_client: ''
tasmota_mqtt_topic: ''
tasmota_mqtt_fulltopic: ''
tasmota_mqtt_no_log: true
If both tasmota_user
and tasmota_password
are filled out, they will be used to authenticate the commands.
If any MQTT settings are filled, a Backlog
command will be run automatically after the other commands.
tasmota_commands
is a list of commands you want to execute. Each command looks like this:
- command: <COMMAND>
value: <VALUE>
For example:
tasmota_commands:
# Set TelePeriod to 10 seconds
- command: TelePeriod
value: 10
# Change TelePeriod based on switch state
- command: Rule1
value: "on Power1#state=0 do TelePeriod 3600 endon on Power1#state=1 do TelePeriod 1 endon"
# Enable Rule1
- command: Rule1
value: 1
# Set up a one-shot for Rule1
- command: Rule1
value: 5
# Set and enable template (note: not a string)
- command: Template
value: {NAME: FooModule, GPIO: [1,2272,1,2304,1,1,0,0,1,1,1,1,1,0], FLAG: 0, BASE: 54}
- command: Module
value: 0 # Template
# Configure multiple TuyaMCU functions
- command: TuyaMCU
value: 11,10
- command: TuyaMCU
value: 12,13
# Disable TuyaMCU fnId
- command: TuyaMCU
value: 11,0
# Set Timer16 to trigger a Rule daily at 06:00
- command: Timer16
value: '{"Enable":1,"Time":"06:00","Window":5,"Days":"1111111","Repeat":1,"Output":1,"Action":3, "Mode":0}'
- command: Rule3
value: "on Clock#Timer=16 do Restart 1 endon"
- command: Rule3
value: 1
- command: Timers
value: 1
# Example for no_log
- command: MqttPassword
value: MySafePassword
no_log: True
Tips
To avoid repeating tasmota_commands
for each host, use something like this:
# Commands for all instances
default_tasmota_commands:
- command: NtpServer1
value: 192.168.0.1
- command: LedState
value: 0
# Specific commands
specific_tasmota_commands:
tasmota001:
- command: FriendlyName1
value: TV
tasmota002:
- command: FriendlyName1
value: HiFi
tasmota_commands: "{{ default_tasmota_commands | union(specific_tasmota_commands[inventory_hostname] | default([])) }}"
Example
Sets the TelePeriod
to 10 seconds for all devices in the tasmota
host group.
- hosts: tasmota_devices
gather_facts: no
vars:
tasmota_commands:
- command: TelePeriod
value: 10
roles:
- tobias_richter.tasmota
License
Apache 2.0
Ansible Role for managing tasmota devices with tasmota commands.
ansible-galaxy install tobias_richter.tasmota