Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How-To : Tasmota with CQC using MQTT
#1
Tasmota is a very popular firmware to flash onto many Web enabled devices that are found for sale in many places.  This all started with the SonOff basic ESP8266 based relay but has expanded quite significantly.

Below are some of the lines that can be used in the cfg file for the various options of the Tasmonta firmware.  At the moment it is just plugs and relays and once I have sorted out the RGB side I will post the cfg lines required to control colour and brightness.

At a minimum a plug/relay will need two fields - One to read the status of the device and one to control it.  There are three options, On, Off and Toggle.  This is a basic setup

Code:
   <Fields>
     
        <!-- ================================================================== -->
        <!-- Sonoff Basic Relay 1                                               -->
        <!-- 192.168.0.                                                         -->
        <!-- Test Relay                                                         -->
        <!-- ================================================================== -->
       
        <Generic Topic="stat/TestRelay/POWER" BaseName="TestRelay" Access="R" FldType="Boolean">
            <PLFmt Type="BinText"/>
            <BoolTextMap FalseOut="OFF" TrueOut="ON">
                <BoolTextVal TarVal="False" MQTTVal="OFF"/>
                <BoolTextVal TarVal="True" MQTTVal="ON"/>
            </BoolTextMap>
        </Generic>
        
       <Generic Topic="cmnd/TestRelay/POWER" BaseName="TestRelay_Cmd" FldType="String" OnConnect=" " Retain="No"
                   Limits="Enum: On, Off, Toggle" Access="W">
           <PLFmt Type="BinText"/>
           <EnumMap>
               <EnumVal FldVal="Off" MQTTVal="OFF"/>
               <EnumVal FldVal="On" MQTTVal="ON"/>
               <EnumVal FldVal="Toggle" MQTTVal="TOGGLE"/>
           </EnumMap>
       </Generic>
</Fields>
The firmware also supports blinking.  The user can define the number of times the relay "blinks" and the time between blinks.  Once blinking has started it can be stopped with the BlinkOff command.  Note that the relay does not publish the change of state when blinking.  Turning off blinking will revert the relay back to its state prior to blinking.

Below is the extended Command for the control of the relay
Code:
           <Generic Topic="cmnd/TestRelay/POWER" BaseName="TestRelay_Cmd" FldType="String" OnConnect=" " Retain="No"
                   Limits="Enum: On, Off, Toggle, Blink, BlinkOff" Access="W">
           <PLFmt Type="BinText"/>
           <EnumMap>
               <EnumVal FldVal="Off" MQTTVal="0"/>
               <EnumVal FldVal="On" MQTTVal="1"/>
               <EnumVal FldVal="Toggle" MQTTVal="2"/>
               <EnumVal FldVal="Blink" MQTTVal="3"/>
               <EnumVal FldVal="BlinkOff" MQTTVal="4"/>
           </EnumMap>
           </Generic>

The fields for controlling the blink time and blink count.  The CQC field for time is in seconds and the drivers converts it to 100th's of seconds.

Becasue the firmware publishes status changes on the same topic in JSON format we need to use the IgnoreNotFnd feature.  This means the field is only updated if the JSON value matches the InPath value otherwise it is ignored.  This stops the driver from putting all the other fields in error that use the same topic when if it finds a match.
Code:
        <Generic Topic="stat/TestRelay/RESULT" BaseName="TestRelay_BlinkCount" Limits="Range:1,32000" FldType="Card" Retain="No"
                   Access="R">
               <PLFmt Type="BinText"/>
               <JSONMap
                InPath="/BlinkCount" IgnoreNotFnd="Yes" >
                <ScaleRangeMap MQMin="0" MQMax="32000" FldMin="0" FldMax="32000"/>
            </JSONMap>
        </Generic>
       
           <Generic Topic="cmnd/TestRelay/BlinkCount" BaseName="TestRelay_BlinkCount_Cmd" FldType="Card" Limits="Range:1,32000" OnConnect=" " Retain="Yes"
                   Access="W">
           <PLFmt Type="BinText"/>
         </Generic>

         <Generic Topic="stat/TestRelay/RESULT" BaseName="TestRelay_BlinkTime" Limits="Range:0,3600" FldType="Float" Retain="No"
                   Access="R">
               <PLFmt Type="BinText"/>
               <JSONMap
                InPath="/BlinkTime" IgnoreNotFnd="Yes">
                <ScaleRangeMap MQMin="0" MQMax="3600" FldMin="0" FldMax="360"/>
            </JSONMap>
        </Generic>
 
           <Generic Topic="cmnd/TestRelay/BlinkTime" BaseName="TestRelay_BlinkTime_Cmd" Limits="Range:0,360" FldType="Float" OnConnect=" " Retain="Yes"
                   Access="W">
           <PLFmt Type="BinText"/>
           <ScaleRangeMap MQMin="0" MQMax="3600" FldMin="0" FldMax="360"/>
         </Generic>
Mykel Koblenz
Illawarra Smart Home
Reply
#2
Here are the Power read and writes as V2 compatible fields.

Semantic Type ContactClosure is always a read only.  Can also be MotionSensor.  Both these are R only

The write field can be Relay, BoolSwitch, LightSwitch or Relay as these are W or R/W and never R

Code:
          <Relay Topic="cmnd/TestRelay/POWER" BaseName="TestRelay" OnConnect=" " Retain="No" Access="W">
          <PLFmt Type="BinText"/>
          <BoolTextMap FalseOut="OFF" TrueOut="ON">
              <BoolTextVal TarVal="False" MQTTVal="OFF"/>
               <BoolTextVal TarVal="True" MQTTVal="ON"/>
          </BoolTextMap>
          </Relay>
          
       <ContactClosure Topic="stat/TestRelay/POWER" BaseName="TestRelay_Status">
           <PLFmt Type="BinText"/>
           <BoolTextMap FalseOut="OFF" TrueOut="ON">
               <BoolTextVal TarVal="False" MQTTVal="OFF"/>
               <BoolTextVal TarVal="True" MQTTVal="ON"/>
           </BoolTextMap>
       </ContactClosure>
Mykel Koblenz
Illawarra Smart Home
Reply
#3
Temperature Sensor V2

This is when a DS18B20 1-wire temp sensor is connected to Tasmota.  The value is published on the topic tele/<MQTT topic>/SENSOR in a JSON formatted payload.  NOte the InPatch value.  This will potentially change if using a different type of sensor that is compatible with Tasmota.

Code:
     <TempSensor  Topic="tele/ESPDev/SENSOR" BaseName="Outdoors" FldType="Float" MinVal="0.0" MaxVal="100.0">
           <PLFmt Type="BinText" />
           <JSONMap
               InPath="/DS18B20/Temperature">
               <ScaleRangeMap MQMin="0.0" MQMax="100.0" FldMin="0.0" FldMax="100.0"/>
           </JSONMap>
      </TempSensor>
Mykel Koblenz
Illawarra Smart Home
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)