How do I view get the speed from MQTT Fan with RF

Hi Guys,

Thanks in advance for you help. first time poster, I am having trouble turning my mqtt data into a percentage using mqttfan

I don’t have any issue controlling the fan, I just want to update home assistant when the remote is used.

I think my issue is converting my payload to a percentage via percentage value template

This is what the payload from my RF Bridge looks like

{"Time":"2024-01-09T06:46:51","RfReceived {"Data":"0x6F7","Bits":12,"Protocol":8,"Pulse":318}} 

This is what my code is

     - unique_id: bedroomfan
       name: "Bedroom Fan"
       command_topic: "cmnd/RFBridge/RFSend"
       command_template: >
         {% if value == 'ON' %}
           {"Data":"0x6F5","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% elif value == 'OFF' %}
           {"Data":"0x6FD","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% endif %}
       percentage_command_topic: "cmnd/RFBridge/RFSend"
       percentage_command_template: > 
         {% if (value >= 1) and (value <= 20) %}
           {"Data":"0x6F7","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% elif (value >= 21) and (value <= 40) %}
           {"Data":"0x6F5","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% elif (value >= 41) and (value <= 60) %}
           {"Data":"0x6EF","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% elif (value >= 61) and (value <= 80) %}
           {"Data":"0x6E7","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% elif (value >= 81) and (value <= 90) %}
           {"Data":"0x6DD","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% elif (value >= 91) and (value <= 100) %}
           {"Data":"0x6DF","Bits":12,"Protocol":8,"Pulse":319,"Repeat":10}
         {% elif is_state('input_boolean.state', 'on') %}
           {"Data":"0x6F5","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% elif is_state('input_boolean.state', 'off') %}
           {"Data":"0x6FD","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% else %}
           {"Data":"0x6FD","Bits":12,"Protocol":8,"Pulse":318,"Repeat":10}
         {% endif %}
       percentage_state_topic: "tele/RFBridge/RESULT"
       percentage_value_template: >
         {% if ({value_json.RfReceived.Data} == '0x6F7') %}
           10
         {% else ({value_json.RfReceived.Data} == '0x6F7') %}
           30
         {% endif %}
       availability:
         - topic: "tele/RFBridge/LWT"
           payload_available: Online
       qos: 1
       retain: true
       optimistic: true 

I don’t have an MQTT Fan, but thought I would give it a shot to help…
In UI->DeveloperTools->Templates, I got the following to work
(Note: I added a ": after RfReceived, otherwise the JSON won’t parse):

{% set test_json = {"Time":"2024-01-09T06:46:51","RfReceived":{"Data":"0x6F7","Bits":12,"Protocol":8,"Pulse":318} } %}
{{ test_json.RfReceived }}         
{% if test_json.RfReceived.Data == "0x6F7" %}
  10
{% else %}
  20
{% endif %}

Thanks for your help, with a bit of tweaking i got it working