IR Fan automation

I wonder if somebody could point me in the right direction. I’m a long time user of Domoticz, and recently moved over to Home Assistant. Although I’ve got the majority of my home automation up and running, I’m struggling to get my head around how to control my IR ceiling fan.

I have a Westinghouse IR fan with 4 states, controller via Logitech Harmony Hub.

In Domz, I used to have a dummy switch, with 4 states (Off, Low, Med and Max). Dependant on the temperature in the room, Domz would call a shell script which would in turn would send the correct IR signal to the fan.

In Home Assistant, I’ve set up 4 scripts for the 4 states which work great from the Scripts screen.

I’ve spent the day at looking at script example, using templated switches, but I’m getting a little lost.

Assuming I have 4 scripts setup and working in Home Assistant (1 = off, 2 = Low, 3 = Med, 4 =Max), below is pseudo code of what I’m trying to achieve.

IF numeric_state of sensor.office_sensor_temperature < 21
run script 1
IF numeric_state of sensor.office_sensor_temperature => 21
run script 2
IF numeric_state of sensor.office_sensor_temperature => 23
run script 3
IF numeric_state of sensor.office_sensor_temperature => 25
run script 4

I’m not sure if I even need to use Scripts in Home Assistant, as I can directly control the fan via the remote.send_command function.

If somebody can point me in the right direction, that would be great.

Thanks in advance.
Darren

Write an automation that uses a service template to call the correct script (scripts are services):

trigger:
  - platform: state
    entity_id: sensor.office_sensor_temperature  # trigger on any change of temperature
action:
  - service_template: >
      {% if states('sensor.office_sensor_temperature')|float < 21 %}
        script.script_1
      {% elif states('sensor.office_sensor_temperature')|float >= 21 %}
        script.script_2
      {% elif states('sensor.office_sensor_temperature')|float >= 23 %}
        script.script_3
      {% elif states('sensor.office_sensor_temperature')|float >= 25 %}
        script.script_4
      {% endif %}

If you wanted to send the remote command instead of using scripts you would use a data_template:

trigger:
  - platform: state
    entity_id: sensor.office_sensor_temperature
action:
  - service: remote.send_command
    data_template:
      entity_id: remote.your_remote
      command: >
        {% if states('sensor.office_sensor_temperature')|float < 21 %}
          command_off
        {% elif states('sensor.office_sensor_temperature')|float >= 21 %}
          command_low
        {% elif states('sensor.office_sensor_temperature')|float >= 23 %}
          command_med
        {% elif states('sensor.office_sensor_temperature')|float >= 25 %}
           command_max
        {% endif %}

You would have to replace the remote entity id and commands with what you have called them.

Excellent, that worked a treat. :+1:

It took a good 10/15 minutes to trigger, however my assumption is HA waits for a temperature change (the trigger) and then runs the automation instead of assessing the current value?

Correct. It only triggers on change of temperature.

Perfect. Thanks for your help :slight_smile:

Which did you use, the service or data template?

There are advantages to both. The service template allows you to add more actions to the scripts later if you want to. The data template version is more compact with no need for the scripts.

I preferred the 2nd, calling the command directly from the automation. I then however made the mistake of viewing via the Automation UI after reloading which messed up the formatting in the yaml file.

So I decided to go with the first, thinking this would allow me to easily modify the scripts in future.

1 Like

Wonder if we could re-visit this.

I’m currently using

trigger:
  - platform: state
    entity_id: sensor.office_sensor_temperature  # trigger on any change of temperature
action:
service_template: |
  {% if states('sensor.office_sensor_temperature')|float < 23 %}
    script.officefanoff
  {% elif states('sensor.office_sensor_temperature')|float >= 23 %}
    script.officefanmin
  {% elif states('sensor.office_sensor_temperature')|float >= 25 %}
    script.officefanmed
  {% elif states('sensor.office_sensor_temperature')|float >= 27 %}
    script.officefanmax
  {% endif %}

This works fine for switching the fan on and off, however doesn’t seem to increase the fan speed with I hit 25 or 27 degrees.

The temp is currently 28 degrees in the room, and the fan is on low. I’ve executed each script, they work as expected, however when I execute the automation it drops it back down to fan low (script.officefanmin)

Do I need to be more explicit with the value, so >= 21 and < 23 and so on?

I’ve tried the below, but I get errors on the logs (Unexpected error for call_service at pos 1: ‘<’ not supported between instances of ‘function’ and ‘int’)

service_template: >
  {% if states('sensor.office_sensor_temperature')|float < 23 %}
    script.officefanoff
  {% elif states('sensor.office_sensor_temperature')|float >= 23 and float < 25
  %}
    script.officefanmin
  {% elif states('sensor.office_sensor_temperature')|float >= 25 and float < 27
  %}
    script.officefanmed
  {% elif states('sensor.office_sensor_temperature')|float >= 27 %}
    script.officefanmax
  {% endif %}

I managed to find an example on the forum for wind direction, and using the below has fixed it
:+1:

service_template: |
  {% if states('sensor.office_sensor_temperature')|float < 23 %}
    script.officefanoff
  {% elif 23 >= states('sensor.office_sensor_temperature')|float <25 %}
    script.officefanmin
  {% elif 25 >= states('sensor.office_sensor_temperature')|float <27 %}
    script.officefanmed
  {% elif states('sensor.office_sensor_temperature')|float >= 27 %}
    script.officefanmax
  {% endif %}

Ok, that didn’t work, the fan just stayed on Max, even when the temperature dropped below 27.

What am I doing wrong?

Ok, for anybody that’s interested, I’ve found the source of the problem.

After adding a dummy sensor, and updating that with Off, Min, Med, Max in each script, I found that this got updated properly.

This led me to look at the rest of the script. Turns out, the problem is with the Logitech Harmony integration.

Looking at the logs, I had load of the below.

Logger: aioharmony.hubconnector
Source: __main__.py:356 
First occurred: 13:04:28 (5 occurrences) 
Last logged: 14:49:39

xx.xx.xx.xx: Connection timed out for hub 8726712
* Sending command FanMed to device 37777547 failed with code 566: Command not found for device id:37777547
* Sending command FanMed to device 37683067 failed with code 566: Command not found for device id:37683067

You can also use this HACS component instead of reinventing the wheel.

Thanks gurbina93, I did look at that first, but couldn’t work out how call my harmony remote at each point.

I’m currently looking to replace my IR fans guts with something smarter (Z-Wave or sonoff), then I’ll take another look.

My seems to be less with HA as such, and more the Logitech Harmony integration.

Never tried Logitech Harmony, but I’m using a Broadlink IR+RF controller and SmartIR. Works well since the component handles everything like if it was a Fan/Climate component.

Not sure if Logitech Harmony works with it (doesn’t seem like it) or how hard would it be to get it working with it but there’s a guy who made his own fork to get it working with Logitech. Assuming they work similarly perhaps it just requires a few little changes to get it working with your Harmony, I actually do I find it odd they haven’t added support for Logitech Harnony

Excellent. Thanks for the response. I’ll take a look :+1:

I know this is an old thread, but I just found it via Google, so it may be useful to others.

The logic was flawed.
If temp < 23
off
elif temp >= 23
min
elif temp >= 25
med
elif temp >= 27
max

After temperature is 23 or above, “min” is called. You no longer do any further checks.

You could simplify the logic:

if <23
off
elif <25
low
elif <27
med
else
max

That leaves less room for mistakes :smile:

1 Like