dalinicus / homeassistant-acinfinity

AC Infinity integration for Home Assistant for UIS based controllers
MIT License
77 stars 4 forks source link

Fan sensor #13

Open grssll opened 1 year ago

grssll commented 1 year ago

When it pulls data from AC is it possible to create sensor.fan for the Fan card in HA? Thank you

dalinicus commented 1 year ago

The only problem I can think of is the UIS protocol doesn't seem to care what type of device is connected, i.e. Lights and Fans are treated identically as far as the data is concerned. I haven't been successful in tracking down where in the data a device type might be consistently provided... but I've been wanting to give it another shot and see if i can't figure that out.

One thought I was tossing around was having users select the correct SensorDeviceClass for each port during configuration.

Of note, I am working on getting control sensors setup right now via #14 which would create sub devices for every port.

Thanks for your suggestion :)

grssll commented 1 year ago

Thank you for consideration.

DanDixon commented 6 months ago

Thanks for creating this integration, @dalinicus. It works great.

In the meantime, if you want to control it as a fan you can add a fan template.

Add the code below to your configuration.yaml file to create a fan entity for the AC Infinity Device.

Note that I renamed the New Device Port 1 to Office Desk Exhaust so replace mentions of office_desk_exhaust to the name of your device.

fan:
  - platform: template
    fans:
      office_desk_exhaust:
        friendly_name: "Office Desk Exhaust Fan"
        value_template: "{{ states('select.office_desk_exhaust_active_mode') }}"
        percentage_template: >
          {{ states('number.office_desk_exhaust_on_power') | int * 10 if is_state('select.office_desk_exhaust_active_mode', 'On') else 0 }}
        availability_template: "{{ states('binary_sensor.office_desk_exhaust_status') }}"
        turn_on:
          service: select.select_option
          data:
            option: "On"
          target:
            entity_id: select.office_desk_exhaust_active_mode
        turn_off:
          service: select.select_option
          data:
            option: "Off"
          target:
            entity_id: select.office_desk_exhaust_active_mode
        set_percentage:
          - service: select.select_option
            data:
              option: "{{ 'On' if percentage > 0 else 'Off' }}"
            target:
              entity_id: select.office_desk_exhaust_active_mode
          - service: number.set_value
            target:
              entity_id: number.office_desk_exhaust_on_power
            data:
              value: "{{ (percentage / 10) | int }}"
        speed_count: 10

This way you can turn on and set the fan speed to max in a script like this (or turn it off by setting the percentage to 0:

service: fan.set_percentage
data:
  percentage: 100
target:
  entity_id: fan.office_desk_exhaust

And you can adjust it using a Fan Mushroom card: image

Or by opening up more_info on the fan like this: image

MRobi1 commented 6 months ago

Modified the template slightly to use the current power sensor to determine on/off and fan speed. Using active_mode did not work for me when using automations setup in the AC Infinity app. All devices just showed as "off"

fan:
  - platform: template
    fans:
      grow_tent_exhaust:
        friendly_name: "Grow Tent Exhaust Fan"
        value_template: >
          {% if is_state('sensor.grow_tent_exhaust_fan_current_power','0') %}
            Off
          {% else %}
            On
          {%endif %}
        percentage_template: >
          {{ states('sensor.grow_tent_exhaust_fan_current_power') | int * 10 if not is_state('sensor.grow_tent_exhaust_fan_current_power','0') else 0 }}
        availability_template: "{{ states('binary_sensor.grow_tent_exhaust_status') }}"
        turn_on:
          service: select.select_option
          data:
            option: "On"
          target:
            entity_id: select.grow_tent_exhaust_fan_active_mode
        turn_off:
          service: select.select_option
          data:
            option: "Off"
          target:
            entity_id: select.grow_tent_exhaust_fan_active_mode
        set_percentage:
          - service: select.select_option
            data:
              option: "{{ 'On' if percentage > 0 else 'Off' }}"
            target:
              entity_id: select.grow_tent_exhaust_fan_active_mode
          - service: number.set_value
            target:
              entity_id: number.grow_tent_exhaust_fan_on_power
            data:
              value: "{{ (percentage / 10) | int }}"
        speed_count: 10