NAME
App::OpenHAP::Tasmota::Device - a Tasmota device as a HAP accessory
SYNOPSIS
use App::OpenHAP::Tasmota::Device;
package My::Switch;
our @ISA = qw(App::OpenHAP::Tasmota::Device);
sub _on_power_update ($self, $state) { ... }
DESCRIPTION
This class is a Tasmota device that is also a Protocol::HAP::Accessory. It owns the MQTT subscriptions, the availability state, the temperature unit, and the power helpers. Every device class in lib/App/OpenHAP/Tasmota/ inherits from it and adds the HAP services of one device kind.
The class is never used on its own. It subscribes and it caches, and it publishes no service.
CONSTRUCTOR
new(%args)
The constructor takes the arguments of Protocol::HAP::Accessory, and these:
mqtt_topic-
The Tasmota topic of the device, without a prefix. Required.
mqtt_client-
The MQTT client. Required.
relay_index-
The relay of a multi-relay device, counted from 1. The default 0 means that the device has one relay and no index.
Every topic follows the default Tasmota FullTopic pattern, %prefix%/%topic%/. OpenHAP requires the device to run with that default.
THE MQTT TOPIC CONTRACT
subscribe_mqtt subscribes to five topics of the device. A subclass that overrides the method must call SUPER::subscribe_mqtt first.
tele/LWT-
The availability of the device.
Onlinealso triggersquery_initial_state. tele/STATE-
The periodic state. It reaches
_process_state_data. tele/SENSOR-
The sensor readings. It reaches
_process_sensor_data, and it also carries theTempUnitthatconvert_temperatureneeds. stat/RESULT-
The answer to a command. It reaches
_process_result_data. stat/STATUS11-
The full state, for reconciliation after a connect. The class unwraps
StatusSTSand hands the content to_process_state_data.
The class publishes to cmnd/Power and cmnd/Status. The power topic carries the relay index, when it applies.
METHODS
subscribe_mqtt()
Subscribe to the five topics above.
query_initial_state()
Ask the device for its full state with Status 11.
is_online()
Report if the last LWT message said Online.
set_power($state)
Publish a power command. $state is 1 for on and 0 for off.
query_status($type)
Ask the device for a status report.
convert_temperature($temp)
Return the temperature in Celsius. The device reports the unit in its SENSOR message, and HAP always wants Celsius.
METHODS A SUBCLASS OVERRIDES
Each one does nothing by default, so a subclass takes only what it needs.
_process_state_data($data)-
The decoded
STATEorSTATUS11payload. The default extracts the power state, so an override callsSUPERfirst. _process_result_data($data)-
The decoded
RESULTpayload. The default extracts the power state. _process_sensor_data($data)-
The decoded
SENSORpayload. _on_power_update($state)-
The power state changed.
$stateis 1 for on and 0 for off.
SEE ALSO
Protocol::HAP::Accessory, App::OpenHAP::Devices, spec/MQTT-Transport.md, spec/MQTT-Control.md, spec/MQTT-State.md