tobias-richter / ansible-tasmota Goto Github PK
View Code? Open in Web Editor NEWAnsible Role for managing tasmota devices with tasmota commands
License: Apache License 2.0
Ansible Role for managing tasmota devices with tasmota commands
License: Apache License 2.0
I first had the issue with Templates but it seems to be consistent for other commands like Timers.
Setting a command like this:
- command: Timer16
value: '{"Enable":1,"Mode":0,"Time":"11:44","Window":0,"Days":"1111111","Repeat":1,"Output":1,"Action":3}'
results in this request (response: invalid json):
/cm?user=&password=&cmnd=Timer16+%7B%27Enable%27%3A+1%2C+%27Mode%27%3A+0%2C+%27Time%27%3A+%2711%3A44%27%2C+%27Window%27%3A+0%2C+%27Days%27%3A+%271111111%27%2C+%27Repeat%27%3A+1%2C+%27Output%27%3A+1%2C+%27Action%27%3A+3%7D
This is due to the fact, that instead of "
only '
is used:
Timer16 {'Enable': 1, 'Mode': 0, 'Time': '11:44', 'Window': 0, 'Days': '1111111', 'Repeat': 1, 'Output': 1, 'Action': 3}
It does not matter, how you escape the value, the followin also fails:
- command: Timer16
value: "{'Enable':1,'Mode':0,'Time':'11:44','Window':0,'Days':'1111111','Repeat':1,'Output':1,'Action':3}"
Also the documented value for Template does not seem to work.
There is still 1.9.0
version on the ansible galaxy.
Thanks
I updated the sonoff dual with tasmota 9.2. So everything latest. The MQTT topic won't get set up right.
I have both these in my ansible:
shortname: "{{ inventory_hostname.split('.')[0] | lower }}"
tasmota_mqtt_topic: "{{ shortname }}"
sonoff-dual.ikenet:
- command: topic
value: "{{ shortname }}"
and from ansible playbook I can see it both from debug and the actual run that the topic is carried ok:
TASK [debug] ************************************************************************************************************
ok: [sonoff-dual.ikenet] => {
"tasmota_commands": [
{
"command": "poweronstate",
"value": 1
},
{
"command": "friendlyname1",
"value": "sonoff-dual"
},
{
"command": "module",
"value": 5
},
{
"command": "topic",
"value": "sonoff-dual"
}
]
}
TASK [debug] ************************************************************************************************************
ok: [sonoff-dual.ikenet] => {
"tasmota_mqtt_host": "mqtt.ikenet"
}
TASK [debug] ************************************************************************************************************
ok: [sonoff-dual.ikenet] => {
"tasmota_mqtt_port": "1883"
}
TASK [debug] ************************************************************************************************************
ok: [sonoff-dual.ikenet] => {
"tasmota_mqtt_client": "sonoff-dual"
}
TASK [debug] ************************************************************************************************************
ok: [sonoff-dual.ikenet] => {
"tasmota_mqtt_topic": "sonoff-dual"
}
TASK [tobias_richter.tasmota : Configure tasmota.] **********************************************************************
changed: [sonoff-dual.ikenet] => (item={'command': 'poweronstate', 'value': 1})
changed: [sonoff-dual.ikenet] => (item={'command': 'friendlyname1', 'value': 'sonoff-dual'})
changed: [sonoff-dual.ikenet] => (item={'command': 'module', 'value': 5})
changed: [sonoff-dual.ikenet] => (item={'command': 'topic', 'value': 'sonoff-dual'})
TASK [tobias_richter.tasmota : Setup MQTT.] *****************************************************************************
changed: [sonoff-dual.ikenet]
so definitely the ansible get's the topic for the role, but it doesn't get set in tasmota. The host specific command for topic should not be needed, but I tried forcing it. However, after such run the topic is "tasmota_%06X" in tasmota GUI.
Hello, I'm receiving the following error, not sure if I'm doing something wrong-
PLAY [test] *****************************************************************************************************************************************************************************************************************************************************************************************************************
TASK [tobias_richter.tasmota : Configure tasmota.] **************************************************************************************************************************************************************************************************************************************************************************
fatal: [TAS_LR_Soundbar.tc.local]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'value'\n\nThe error appears to be in '/home/josh/roles/tobias_richter.tasmota/tasks/main.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: \"Configure tasmota.\"\n ^ here\n"}
Any advice would be appreciated.
Hi,
Before anything else, thank you for this role. It's great.
When the password is defined in an Ansible Vault, which is my case, the password in the status_params
dictionary is of type ansible.parsing.yaml.objects.AnsibleVaultEncryptedUnicode
. As a consequence, it is incorrectly processed by the requests.get() method: if password is 123, the resulting uri is: cm/?user=theuser&password=1&password=2&password=3
.
The simplest solution is to use str()
when building the status_params
dictionary. For extra safety I would apply this to all the values (because the username and the command can also be defined in the Vault).
I will submit a PR with a proposal to solve this issue.
Regards,
Nuno
Hi,
first of all, thanks for doing the role, looks really nice. I have a bunch of tasmota devices at home, and immediately went and tried this role. However, I noticed it won't work for the older modules that I have. At least that's what I thinki is the reason. The module get's some sort of wrong answer for the status query at the beginning. So perhaps it would be good to have some version check or something? Or handle different answers differently?
It seems to come down to this difference in answer:
╰─$ curl http://sonoff-rv/cm\?cmnd\=poweronstate
{"PowerOnState":1}
╰─$ curl http://sonoff-tp/cm\?cmnd\=poweronstate
RESULT = {"PowerOnState":1}
I don't know exactly when the format has changed, but seems the older ones have "RESULT = " before the json. This fails the role. I just went to try OTA update to one of my tasmota light swithces, but it died during the process.... I'll report back if I get it back alive one day. The version was 5.11.
When running:
ansible-playbook playbooks/adjust_reporting_tasmotas.yaml
with the following playbook
- hosts: tasmotas
gather_facts: no
tasks:
- name: Ensure device reports status
include_role:
name: tobias_richter.tasmota
vars:
tasmota_commands:
- command: Teleperiod
value: 200
I get the following error:
han@MBP2018-2 Ansible % ansible-playbook playbooks/upgrade_tasmotas.yaml
PLAY [tasmotas] ***********************************************************************************************************************************************************
TASK [Ensure device reports status] ***************************************************************************************************************************************
TASK [tobias_richter.tasmota : Configure tasmota.] ************************************************************************************************************************
objc[75669]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[75669]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
This is related to:
ansible/ansible#32499 : OSX crash complaining of operation in progress in another thread when fork() was called #32499
Ist there anything I can do to prevent the error so this playbook is run?
Hey,
when setting the mqtt password using the ansible role, it is detected as change each time. Also the password is published in plaintext inside the playbook output:
changed: [tasmota_balkon_chirp] => (item={'command': 'MqttPassword', 'value': 'blubblub'})
I'm not sure, if we can solve the first problem, is there any best practive if such configs should return a "changed" or "ok"?
22:06:34.603 CMD: mqttpassword
22:06:34.611 MQT: stat/tasmota_balkon_chirp/RESULT = {"MqttPassword":"****"}
For the second problem: It is also relevant for the following configs:
I guess we could set the no_log
flag for all commands that contain "password", what do you think?
When you change the FriendlyName
value of a device, Ansible will always report "changed", no matter if the name is the same as before.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.