How to control ceiling fan with build-in lights

I have a ceiling fan with built-in lights that could be controlled remotely, but the controls broke.
So I replaced the control with the MOES “Smart light switch module (2 gang)”.
The fan should start running when the living room gets too “hot” (27.5 degrees) and the built-in lamps should turn on when the “brightness” of the HUE lighting is higher than 98%.

The problem mainly arises in the control of the built-in lamps.
When the HUE lights are off, the “brightness” attribute is missing.
What I have made is not reliable enough. Sometimes the lights do not turn on or off when the HUE lights turn on or off.
Controlling the fan also works unreliable and should be done differently, but how?

Can this be accomplished in any other way?

Here my both automations:

alias: Plafond Licht
description: ''
trigger:
  - platform: state
    entity_id: light.woonkamer
condition: []
action:
  - service: |-
      {% if state_attr("light.woonkamer", "brightness") | int > 250 %}
        switch.turn_on
      {% else %}
        switch.turn_off
      {% endif %}
    target:
      entity_id: switch.woonkamer_fan_light_l2
mode: single

alias: Plafond Fan
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.woonkamer_temperature
    above: '27.5'
  - platform: numeric_state
    entity_id: sensor.woonkamer_temperature
    below: '27.5'
condition: []
action:
  - service: |-
      {% if states('sensor.woonkamer_temperature') | float > 27.5 %}
        switch.turn_on
      {% else %}
        switch.turn_off
      {% endif %}
    target:
      entity_id: switch.woonkamer_fan_light_l1
mode: single

Think for the attribute a default(0) filter should do the trick. But the automation might trigger quite a lot with an empty state trigger.

For the fan I would add some hysteresis, like 1 or halve a degree.

About different, yeah, you could use a chooser instead of templates.