fmtr / hct

A Tasmota Berry Script library to greatly simplify the process of exposing Home Assistant controls (e.g. Pull-down Lists, Number Sliders, Sensors, etc.) from a Tasmota device - and handling the communication between both sides.
Apache License 2.0
10 stars 2 forks source link

Variables in Tasmota topic not being evaluated #1

Closed AgentFire closed 1 year ago

AgentFire commented 1 year ago

Hi.

I've discovered this repo while searching in how to make berry-tasmota-HA work, but I've run into an issue.

import hct

hct.Button(        
    'Upgrade Tasmota',
    nil,
    'mdi:update',
    /value->tasmota.cmd("upgrade 1")
)

You see, when I put this simple code of into the autoexec.be file, my Tasmota32 (DevKit) starts up well (even compiles the file into a new one, with .bec extension).

But no button appears in my home assistant. There are two integrations actually, the standard Mosquitto broker and a Tasmota one. The device is only shown in Tasmota, and all the entities it provides are the default ones - SSID, Restart Reason, etc.

No button entity.

I have tried running the same code in the Berry Console, and again, no errors (everything runs well, the Button instance is returned). But alas, still no button in the Tasmota Device in HA.

I understand that there is no Tuya or whatever in my setup, so am I right to assume it is not required in any way? Why in that case nothing would appear? What can I do to fix that?

AgentFire commented 1 year ago

Here are some additional info from HA logs:

Logger: homeassistant.components.mqtt.discovery
Source: components/mqtt/discovery.py:108
Integration: MQTT ([documentation](https://www.home-assistant.io/integrations/mqtt), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+mqtt%22))
First occurred: 00:24:47 (18 occurrences)
Last logged: 19:15:16

Received message on illegal discovery topic 'homeassistant/button/tasmota_%06X/tasmota_06x_240ac45a19a4_upgrade_tasmota/config'
Received message on illegal discovery topic 'homeassistant/sensor/tasmota_%06X/tasmota_06x_240ac45a19a4_status/config'
Received message on illegal discovery topic 'homeassistant/sensor/tasmota_%06X/tasmota_06x_240ac45a19a4_sensortest/config'
Received message on illegal discovery topic 'homeassistant/number/tasmota_%06X/tasmota_06x_240ac45a19a4_number123/config'

SensorTest, Number123 are being my own attempts to "see" your instruments in HA, it seems.

AgentFire commented 1 year ago

Seems the issue was with Tasmota's _%06X not being replaced. Changed it in the MQTT config section and the button appeared!

But perhaps this line needs refining: https://github.com/fmtr/hct/blob/master/hct.be#L48 as it returns this tasmota_%06X value instead of the actual one.

ejohb commented 1 year ago

I realized this was open/closed quite quickly, but I'm still surprised I missed it! Yes, it's taking the topic literally. I'll see what I can do about that.