Hi, first post did some searching but need some help or pointers.
As the subject says I put an ESPHome inside of an Ikea AIr Purifier that I want to use with my 3D printer. Along with the ESPHome there is an SGP41 VoC sensor, DC power meter and a GPIO switch to trigger the only button that is controlled by a virtual switch in the config.yaml. When the switch is triggered it “presses the button” for 200ms and shuts off. As it cycles through speeds I see the volts, amps and watts consumed at each setting. All the hardware works perfectly fine. The button starts at “Off”, when you I trigger the virtual switch it goes to low then med then high and back to off. I want to use wattage ranges to determine what the speed is at or if its off.
I have been trying to figure out using the fan template to control this with off, low,med,high like a ceiling fan. I have seen many examples including: https://community.home-assistant.io/t/king-of-fans-mr101z-missing-max-setting/267131/37
I get nothing at all showing speed in the templage. I am really new to using ESPHome and configuring an ESP8266 or ESP32. I first set up a Garage Door opener that reads the signal from the magnetic rail sensors to determine if its open or closed and trigger then door open/ close including a template with the up arrow, stop button and down arrow which all works so I have had some success.
Perhaps the way to do this is via code in the ESP8266 but I have not done anything like that yet?
Right now I am stuck trying to understand the different parts of the template value_template, percentage_template and the relationships therein. I have a script that I built from the above link along with the virtual device but like I said, nothing happens when I use the virtual switch or the one from the ESPHome. It always says its off.
Anyone have any guidance or pointers such as other posts to read etc?
Ultimately I plan to use NodeRed to control fan speed based on VoC sensor levels which won’t need any of this but I would like to be able to press medium from the cirtual button have it trigger the button twice from off to medium.
Thanks in advance!
config.yaml stuff I have tried, no doubt there are mistakes:
script:
set_air_purifier_speed:
fields:
percentage:
description: The percentage that should be set.
example: '0'
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ percentage == 0 }}'
sequence:
- service: fan.turn_off
target:
entity_id: fan.air_purifier_3d_printer
- conditions:
- condition: template
value_template: '{{ percentage > 0 }}'
sequence:
- service: number.set_value
target:
entity_id: number.air_purifier_3d_printer_favorite_level
data:
value: '{{ ((percentage - (100/3 | round(0))) * 3/100) | round(0)}}'
- service: fan.set_preset_mode
target:
entity_id: fan.air_purifier_3d_printer
data:
preset_mode: Favorite
- service: fan.turn_on
target:
entity_id: fan.air_purifier_3d_printer
mode: single
turn_air_purifier_on:
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ state_attr(''fan.air_purifier_3d_printer'', ''percentage'') == 0}}'
sequence:
- service: fan.set_percentage
target:
entity_id: fan.air_purifier_3d_printer
data:
percentage: 7
- conditions:
- condition: template
value_template: '{{ state_attr(''fan.air_purifier_3d_printer'', ''percentage'') > 0 }}'
sequence:
- service: fan.set_preset_mode
target:
entity_id: fan.air_purifier_3d_printer
data:
preset_mode: Favorite
- service: fan.turn_on
data:
entity_id: fan.air_purifier_3d_printer
mode: single
fan:
- platform: template
fans:
air_purifier_3d_printer:
unique_id: "air_purifier_3d_printer"
friendly_name: "3D Printer Air Purifier"
value_template: "{{ states('fan.air_purifier_3d_printer') }}"
percentage_template: >
{{ ((states('number.air_purifier_3d_printer_favorite_level') | int + 1) * 100/3) | round(0) }}
turn_on:
service: script.turn_air_purifier_on
turn_off:
service: fan.turn_off
data:
entity_id: fan.air_purifier_3d_printer
set_percentage:
service: script.set_air_purifier_speed
data_template:
percentage: "{{ percentage }}"
speed_count: 3