How to use Value Template with a power monitor sensor to indicate a Fan State correctly

Hi, its kind of difficult to describe it clearly in the title.
Need some help in the configuration.yaml coding.

I am using Hassio on RPi4, also using Zigbee2mqtt.
I use Tuya IR remote to control my Fan.
I created a scene in Tuya to toggle the fan power. and i can call the scene in HA to turn on/off the fan (actually just toggle power)
I mainly use Picture element to control my fan.
I have learned how to setup fake switch by using “input boolean” and “switch”

input_boolean:
  living_fan_state: null 

switch
  - platform: template
    switches:
      living_fan:
        value_template: "{{ is_state('input_boolean.living_fan_state', 'on') }}"
        turn_on:
          - service: input_boolean.turn_on
            entity_id: input_boolean.living_fan_state
          - service: scene.turn_on
            entity_id: scene.living_fan_power
        turn_off:
          - service: input_boolean.turn_off
            entity_id: input_boolean.living_fan_state
          - service: scene.turn_on
            entity_id: scene.living_fan_power

The above was working, but the fan icon doesn’t show the correct state if we manually turn on the fan. So I learn that I could also add a power monitor switch on the fan to detect the power value, thereby use this value to feedback if the fan is OFF or ON for the ICON to display accurate state, even if someone manually switch on the fan

I am using a Xiaomi Power Plug, with power monitoring.
and the detail of Xiaomi plug look like this, I know that the power will be >10W if the fan is turn on at Speed1, Speed2 >20W, Speed3>30W

So I try to use the power monitor value to reflect the correct status of my fan. So that my ICON can display state correctly. I tried the following but it doesn’t work. I know my understanding of Template is very poor, hope someone could give me guidance.
First I would just like to get my Fan Icon to display the correct ON/OFF state.
2nd, if possible, I would like my fan Icon (animated GIF) to display according to Fan speed1 or Speed2 or Speed3.

below is my non-working code:

input_boolean:
  living_fan_state: null 

switch
  - platform: template
    switches:
      living_fan:
        value_template: "{{ is_state('sensor.xiaomi_plug_power') > 10 }}"
        turn_on:
          service: scene.turn_on
          data:
            entity_id: scene.living_fan_power   #scene to toggle my fan power
        turn_off:
          service: scene.turn_on
          data:
            entity_id: scene.living_fan_power

Appreciate your kind help in my learning journey, Thanks
I read templating in the HA documentation but I couldn’t figure out…

Thought it will be good to show my lovelace - picture element as well,

  - entity: switch.living_fan
    state_image:
      'off': /local/fanoff.gif?v=1
      'on': /local/fanon.gif?v=1
    style:
      left: 59%
      top: 87%
      transform: scale(0.7)
      width: 5%
    tap_action:
      action: toggle
    type: image

You can test your templates in Dev Tools/templates.

is_state only tests on a specific value, try

value_template: "{{ states('sensor.xiaomi_plug_watt') > 10 }}"

EDIT: Maybe convert to float.

value_template: "{{ states('sensor.xiaomi_plug_watt') | float > 10 }}"

Sorry there is a typo in my example.
It should be “sensor.xiaomi_plug_power” instead of “sensor.xiaomi_plug_watt”
anyway, there is no typo in my actual code… I have edited my post to “plug_power”

Thanks @VDRainer, I tried all the combo you suggested, with 'is_", without “is_”
With “float” without “float” all not working.

I have not learned how to test my code in Dev Tools/Template that you suggested. Thanks for your tips, I will try to figure out how to test my code…

Hi @VDRainer,
This one works, I missed out the “s” in the state’s’ when I tried earlier.
Thanks.

One small glitch, there is up to 2minutes delay for Xiaomi Plug to refresh and report Owatt when the fan is turn off. Hence there will be same delay for my ICON to change state to OFF. Is there a way to force xiaomi plug to refreh faster?

Thanks for your help.

Hi, is there any suggestion for me to approach my 2nd objective? Thanks.