Fan: on_turn_off doesn't work with templates

Hi everyone,

I’m testing a fan and the trigger on_turn_off doesn’t seem to work. on_turn_on works however.

I tested all different possibilities I know - see in the code below. None of them is working.

Does someone see the problem here?

fan:
  - platform: speed
    output: ${devicename}_fan_output
    name: ${devicename}_fan
    id: ${devicename}_fan
    speed_count: 100 
    on_speed_set:
    - sensor.template.publish:
        id: ${devicename}_dashboard_helper_fan_speed
        state: !lambda 'return(id(${devicename}_fan).speed);'
    on_turn_off: 
    - sensor.template.publish:
        id: ${devicename}_dashboard_helper_fan_speed
        state: !lambda 'return 0;'
    - sensor.template.publish:
        id: ${devicename}_dashboard_helper_fan_speed
        state: 0.0
    - sensor.template.publish:
        id: ${devicename}_dashboard_helper_fan_speed
        state: !lambda 'return 0.0;'
    - id(${devicename}_dashboard_helper_fan_speed).publish_state(0.0);

Can’t see anything obvious - but the fan is on when you try and trigger? Because if the fan is already off, fan.on_turn_off won’t trigger.

Only thing I can think of…

The trigger fan_turn_off works fine, I tested it with switches. It just doesn’t work with the lambda-Code…

Maybe this function has never been integrated with lambda?

Did someone tried that already?