Made my Dumb 433Mhz roof FAN a bit smarter

After watching @DrZzs

and doing it I could tasmota to lean the rf codes It has 4 speeds

high med low off

so I created a script for each one and MQTT sensor which keep track of the Speed

the two Sensor

- platform: mqtt
  name: "Lounge Fan Status"
  state_topic: "home/lounge-fan"

- platform: mqtt
  name: "Lounge Fan cmnd"
  state_topic: "home/lounge/fan/cmnd/FanSpeed"


now the Scripts


lounge_fan_3:
  alias: lounge fan Speed 3
  sequence:
    - service: mqtt.publish
      data:
        topic: "cmnd/RF_Bridge_raw/Backlog"
        payload: "RFRAW AA B0 1E 03 08 017C 02E4 2620 28090909181818180909090909090909180909090909 55 RFRAW 0"
    - service: mqtt.publish
      data:
        topic: "home/lounge-fan"
        payload: "3"
    - service: mqtt.publish
      data:
        topic: "home/lounge/fan/cmnd/FanSpeed"
        payload: "on"
  mode: single

lounge_fan_2:
  alias: lounge fan Speed 2
  sequence:
    - service: mqtt.publish
      data:
        topic: "cmnd/RF_Bridge_raw/Backlog"
        payload: "RFRAW AA B0 1E 03 08 0172 02E4 2620 28090909181818180909090909090918090909090918 55 RFRAW 0"
    - service: mqtt.publish
      data:
        topic: "home/lounge-fan"
        payload: "2"
    - service: mqtt.publish
      data:
        topic: "home/lounge/fan/cmnd/FanSpeed"
        payload: "on"
  mode: single

lounge_fan_1:
  alias: lounge fan Speed 1
  sequence:
    - service: mqtt.publish
      data:
        topic: "cmnd/RF_Bridge_raw/Backlog"
        payload: "RFRAW AA B0 1E 03 08 0172 02E4 2620 28090909181818180909090909090918180909091809 55 RFRAW 0"
    - service: mqtt.publish
      data:
        topic: "home/lounge-fan"
        payload: "1"
    - service: mqtt.publish
      data:
        topic: "home/lounge/fan/cmnd/FanSpeed"
        payload: "on"
  mode: single

lounge_fan_0:
  alias: lounge fan Speed 0
  sequence:
    - service: mqtt.publish
      data:
        topic: "cmnd/RF_Bridge_raw/Backlog"
        payload: "RFRAW AA B0 1E 03 08 017C 02E4 2620 28090909181818180909090909090909090918181818 55 RFRAW 0"
    - service: mqtt.publish
      data:
        topic: "home/lounge-fan"
        payload: "0"
    - service: mqtt.publish
      data:
        topic: "home/lounge/fan/cmnd/FanSpeed"
        payload: "off"
  mode: single

NOTE the script name and the payload of the MQTT

now the fan controler bit

- platform: mqtt
  name: "Lounge Fan"
  state_topic: "home/lounge/fan/cmnd/FanSpeed"
  command_topic: "home/lounge/fan/cmnd/FanSpeed"
  speed_state_topic: "home/lounge-fan"
  speed_command_topic: "home/lounge-fan"
  payload_on: "on"
  payload_off: "off"
  payload_low_speed: "1"
  payload_medium_speed: "2"
  payload_high_speed: "3"
  speeds:
    - low
    - medium
    - high

now the bit that join them

I want the right script to run when I select the speed

so could used the new choose option (still getting head around it)

- id: b12c44a8-d707-4892-9f75-c84c6927dab4
  alias: Lounge Fan Control
  initial_state: true
  trigger:
    - entity_id: sensor.lounge_fan_status
      platform: state
  action:
  - data_template:
      entity_id: script.lounge_fan_{{ trigger.to_state.state }}
    service: script.turn_on

now the tidy ups

- id: c9fe33f8-07a1-4bf3-9bd5-2fd144d4dcd6
  alias: Lounge Fan Status right
  trigger:
  - entity_id: sensor.lounge_fan_cmnd
    platform: state
    to: 'off'    
  action:
    - service: mqtt.publish
      data:
        topic: "home/lounge-fan"
        payload: 0 

as I have all the right bits to make a switch so

  - platform: template
    switches:
      lounge_fan: 
        icon_template: mdi:fan
        friendly_name: Lounge Fan
        value_template: '{{ is_state("sensor.lounge_fan_cmnd", "on") }}'
        turn_on:
          service: script.turn_on
          data:
            entity_id: script.lounge_fan_1
        turn_off:
          service: script.turn_on
          data:
            entity_id: script.lounge_fan_0

putting all together

here the code

cards:
  - cards:
      - entity: climate.lounge_fan
        name: Lounge Fan
        type: 'custom:simple-thermostat'
        step_layout: row
        control:
          _headings: false
    type: horizontal-stack
  - cards: null
    entities:
      - entity: fan.lounge_fan
        type: 'custom:fan-control-entity-row'
        name: Fan
      - entity: switch.lounge_fan
    type: entities
  - cards:
      - align_state: center
        entities:
          - color: '#11A579'
            entity: sensor.bt_lounge_temperature
            index: 0
            name: Lounge
        type: 'custom:mini-graph-card'
    type: horizontal-stack
type: 'custom:vertical-stack-in-card'

cant take credit for the lovelace found that in here.

3 Likes

Make Smarter

what about working out the difference between the room temp and the climate setpoint

do some maths

    lounge_factor: 
      friendly_name: Lounge Factor
      value_template: >-
        {%set temp_indoor = states.sensor.bt_lounge_temperature.state | float %}
        {%set temp_fan = state_attr("climate.lounge_fan","temperature") %}
        {%set  factor = (temp_indoor - temp_fan)|int %}
        {{factor}}

now I get a Number

add a Input_boolean

  lounge_auto:
    name: Lounge Auto
    initial: off

so other automation

- id: 4d586798-4280-49e7-afc0-0e675bb30dbd
  alias: Auto Lounge Fan Control
  initial_state: true
  trigger:
  - platform: state
    entity_id: sensor.lounge_factor
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.lounge_auto
      state: 'on'
    - condition: numeric_state
      entity_id: sensor.lounge_factor
      above: 0
  action:
  - data_template:
      entity_id: script.lounge_fan_{{ trigger.to_state.state }}
    service: script.turn_on

so now if as the room get warmer the fan speed should increase and decrease and it get cooler

1 Like

I’m currently trying to implement this into my HA and I’m stuck at this point, I have added it into my config.yaml