Template Fan not updating State correctly

So, trying to get my fans working, but one of my fans seems to not be displaying the correct state.

Look at the interesting display as a result of a template and also the States service returning a different state for input_boolean.b1_fan_state:

And I get this weird error in my logs:

Logger: homeassistant.helpers.service
Source: helpers/service.py:129
First occurred: 09:54:15 (7 occurrences)
Last logged: 11:25:36
Unable to find referenced entities input_select.b1_fan_speed

Here is my code:
Configuration

input_boolean:
  b1_fan_state:

input_select:
  b1_fan_speed:
    options:
      - "33"
      - "66"
      - "100"
fan:
  - platform: template
    fans:
      b1_fan:
        friendly_name: "Bedroom 1 Fan"
        value_template: "{{ states('input_boolean.b1_fan_state') }}"
        percentage_template: "{{ states('input_select.b1_fan_speed') }}"
        turn_on:
          service: script.fan_on
          data:
            room: "b1"
        turn_off:
          service: script.fan_off
          data:
            room: "b1"
        set_percentage:
          service: script.fan_set_speed
          data:
            percentage: "{{ percentage }}"
            room: "b1"

Scripts

fan_set_speed:
  alias: Fan (speed)
  mode: queued
  sequence:
    - service: input_select.select_option
      target:
        entity_id: input_select.{{ room }}_fan_speed
      data:
        option: "{{ percentage }}"
    - delay:
        seconds: 2
    #Remove below service/line if you don't want to start fan on slider change#
    - service: script.fan_on
      data:
        room: "{{ room }}"

fan_off:
  alias: Fan Off
  mode: queued
  sequence:
    - service: input_boolean.turn_off
      target:
        entity_id: input_boolean.{{ room }}_fan_state
    - delay:
        seconds: 2
    - service: remote.send_command
      data:
        entity_id: remote.rmpro_remote
        command: >
          {% if room == "b1"  %}
          b64:
          {% elif room == "b2"  %}
          b64:
          {% elif room == "b3"  %}
          b64:
          {% elif room == "l1"  %}
          b64:
          {% elif room == "d1"  %}
          b64:
          {% endif %}
    - service: input_boolean.turn_off
      target:
        entity_id: input_boolean.{{ room }}_fan_state
fan_on:
  alias: Fan On
  mode: queued
  sequence:
    - service: input_boolean.turn_on
      target:
        entity_id: input_boolean.{{ room }}_fan_state
    - service: "script.fan_{{ states('input_select.' ~ room ~ '_fan_speed') }}"
      data:
        room: "{{ room }}"

fan_33:
  alias: Fan (min)
  mode: queued
  sequence:
    - service: input_text.set_value
      target:
        entity_id: input_select.{{ room }}_fan_speed
      data:
        value: "33"
    - service: remote.send_command
      data:
        entity_id: remote.rmpro_remote
        #Variables Below
        command: >
          {% if room == "b1"  %}
          b64:
          {% elif room == "b2"  %}
          b64:
          {% elif room == "b3"  %}
          b64:
          {% elif room == "l1"  %}
          b64:
          {% elif room == "d1"  %}
          b64:
          {% endif %}
fan_66:
  alias: Fan (med)
  mode: queued
  sequence:
    - service: input_text.set_value
      target:
        entity_id: input_select.{{ room }}_fan_speed
      data:
        value: "66"
    - service: remote.send_command
      data:
        entity_id: remote.rmpro_remote
        #Variables Below
        command: >
          {% if room == "b1"  %}
          b64:
          {% elif room == "b2"  %}
          b64:
          {% elif room == "b3"  %}
          b64:
          {% elif room == "l1"  %}
          b64:
          {% elif room == "d1"  %}
          b64:
          {% endif %}
fan_100:
  alias: Fan (max)
  mode: queued
  sequence:
    - service: input_text.set_value
      target:
        entity_id: input_select.{{ room }}_fan_speed
      data:
        value: "100"
    - service: remote.send_command
      data:
        entity_id: remote.rmpro_remote
        #Variables Below
        command: >
          {% if room == "b1"  %}
          b64:
          {% elif room == "b2"  %}
          b64:
          {% elif room == "b3"  %}
          b64:
          {% elif room == "l1"  %}
          b64:
          {% elif room == "d1"  %}
          b64:
          {% endif %}

You have too many cooks in the pot. Get rid of the input_boolean and only use an input number to store the ‘on/off’ state.

Make 1 script that handles everything or 1 script per room. I made one for you that handles everything. You can’t use queue, things won’t respond the way you expect. You should be using parallel so that you can run multiple switches without them impacting each other (as long as you specify a separate room). Also, percentage uses a slider so you need input_numbers not input_selects.

Input Number

input_number:
  b1_fan_speed:
    name: b1 fan speed holder (Not for use!)
    min: 0
    max: 100
    step: 1

Script

set_fan:
  alias: Set Fan
  mode: parallel
  fields:
    room:
      description: The room
      example: b1
    percentage:
      description: The room percentage
      example: 100
      
  variables:
    rooms:
      b1:
      - b64:  # THE CODE FOR OFF
      - b64:  # THE CODE FOR 33%
      - b64:  # THE CODE FOR 66%
      - b64:  # THE CODE FOR 100%
      b2:
      - b64:  # THE CODE FOR OFF
      - b64:  # THE CODE FOR 33%
      - b64:  # THE CODE FOR 66%
      - b64:  # THE CODE FOR 100%
      b3:
      - b64:  # THE CODE FOR OFF
      - b64:  # THE CODE FOR 33%
      - b64:  # THE CODE FOR 66%
      - b64:  # THE CODE FOR 100%
      l1:
      - b64:  # THE CODE FOR OFF
      - b64:  # THE CODE FOR 33%
      - b64:  # THE CODE FOR 66%
      - b64:  # THE CODE FOR 100%
      d1:
      - b64:  # THE CODE FOR OFF
      - b64:  # THE CODE FOR 33%
      - b64:  # THE CODE FOR 66%
      - b64:  # THE CODE FOR 100%
    current: >
      {{ rooms.get(room) | default([]) }}
    percent: >
      {{ percentage | int(0) }}
    index: >
      {%- if percent <= 0 %}0
      {%- elif percent <= 33 %}1
      {%- elif percent <= 66 %}2
      {%- elif percent <= 100 %}3
      {%- else %}none
      {%- endif %}
    command: >
      {%- set current = rooms.get(room) %}
      {%- if current and index is not none %}
        {{ current[index] }}
      {%- else %}
        none
      {%- endif %}
    we_have_command: >
      {{ command is not none }}
  sequence:
    - condition:
      - condition: template
        value_template: "{{ we_have_command }}"
    - service: input_number.set_value
      target:
        entity_id: input_number.{{ room }}_fan_speed
      data:
        value: "{{ percent }}"
    - service: remote.send_command
      target:
        entity_id: remote.rmpro_remote
      data:
        command: "{{ command }}"

Fan

  - platform: template
    fans:
      b1_fan:
        friendly_name: "Bedroom 1 Fan"
        value_template: "{{ states('input_number.b1_fan_speed') | int(0) > 0 }}"
        percentage_template: "{{ states('input_number.b1_fan_speed') }}"
        turn_on:
          service: script.turn_on
          target:
            entity_id: script.set_fan
          data:
            room: b1
            percent: 100
        turn_off:
          service: script.turn_on
          target:
            entity_id: script.set_fan
          data:
            room: b1
            percent: 0
        set_percentage:
          service: script.turn_on
          target:
            entity_id: script.set_fan
          data:
            room: b1
            percentage: "{{ percentage }}"

If you want 3 preset modes, then you’ll have to use preset modes. But you’d follow similar logic. I can help with that if you need it. It’s considerably different for the script variables section.

Sorry for the delay, I’ve been caught up in life admin for the last few months.

Thank you SO much for your assistance on this.

Unfortunately, I cannot get your script to work… Some issues with the following:
image
EDIT: Fixed error by adding additional indent.

Getting an error on script call:

“Failed to call service fan/set_percentage. extra keys not allowed @ data[‘room’]”

2022-04-01 13:09:06 ERROR (MainThread) [homeassistant.components.template.fan] Received invalid fan is_on state: False. Expected: on, off
2022-04-01 13:10:35 ERROR (MainThread) [homeassistant.helpers.script.bedroom_3_fan] Bedroom 3 Fan: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['room']

My fans only work on the 3 preset mode (low, med, high, off).

@petro would you know how to fix this?