Open richardholst opened 3 years ago
I ended up creating my own, using:
The schema I used was slightly different than the one used here: https://jcallaghan.com/2020/03/can-you-iot-an-airwick-air-freshener/
Also, difference to the article mentioned above: my AirWick had 1.5V motor, therefore I ended up using the original battery case for the motor.
The connection schema is as following:
18650 Battery Case USB-A -> ESP32 microUSB
ESP32 GPIO 21 Pin -> Relay S (the left one)
ESP32 5V Pin -> Relay Positive (the middle one)
ESP32 GND Ping -> Relay Minus (the right one)
For the motor I did the following:
The ESPHome configuration looks like this:
esphome:
name: airwick-hallway
platform: ESP32
board: esp-wrover-kit
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Uncomment the following line if renaming the node
# use_address: airwick-hallway.local
use_address: 192.168.1.126
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "AirWick Hallway Fallback"
password: "fallback Passw0rd"
captive_portal:
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
api:
ota:
switch:
- platform: gpio
pin:
number: 21
name: "AirWick"
id: airwickHallway
- platform: restart
name: "AirWick Hallway Restart"
id: airwickHallwayRestart
- platform: template
name: "AirWick Hallway Switch"
id: airwickHallwayTemplate
icon: "mdi:air-horn"
turn_on_action:
- switch.turn_on: airwickHallway
- delay: 1s
- switch.turn_off: airwickHallway
mqtt:
broker: !secret mqtt_broker
discovery: True
username: !secret mqtt_user
password: !secret mqtt_password
topic_prefix: "airwickHallway"
on_message:
- topic: "airwickHallway/trigger"
then:
- switch.turn_on: airwickHallwayTemplate
Additionally I created one automation with 3 different conditions, few Input Datetimes for the intervals and this panel:
My automation is as following:
- id: hallway_airwick_intervals
mode: restart
alias: AirWick hallway - Intervals
trigger:
- platform: time_pattern
minutes: "*"
action:
- choose:
- conditions:
- condition: template
alias: "No movement in Hallway and frontdoor closed"
value_template: "{{ is_state('group.hallway_motion_door', 'off') }}"
- condition: template
alias: "Status - Someone Home"
value_template: "{{ is_state('group.all_tracker_devices', 'home') }}"
- condition: template
alias: "Last time activated more than defined interval (in this example 30 minutes)"
value_template: "{{ as_timestamp(state_attr('script.hallway_press_twice', 'last_triggered')) < (as_timestamp(now()) - as_timestamp('1970-01-01T' + states('input_datetime.airwick_hallway_status_home_interval') + 'Z')) }}"
sequence:
- service: script.hallway_press_twice
- conditions:
- condition: template
alias: "No movement in Hallway and frontdoor closed"
value_template: "{{ is_state('group.hallway_motion_door', 'off') }}"
- condition: template
alias: "Status - No One Home"
value_template: "{{ not is_state('group.all_tracker_devices', 'home') }}"
- condition: template
alias: "Last time activated more than defined interval (in this example 1 hour)"
value_template: "{{ as_timestamp(state_attr('script.hallway_press_twice', 'last_triggered')) < (as_timestamp(now()) - as_timestamp('1970-01-01T' + states('input_datetime.airwick_hallway_status_away_interval') + 'Z')) }}"
sequence:
- service: script.hallway_press_twice
- conditions:
- condition: template
alias: "No movement in Hallway and frontdoor closed"
value_template: "{{ is_state('group.hallway_motion_door', 'off') }}"
- condition: template
alias: "Status - Everyone Sleeping"
value_template: "{{ is_state('binary_sensor.everyone_home_sleeping', 'on') }}"
- condition: template
alias: "Last time activated more than defined interval (in this example 2 hours)"
value_template: "{{ as_timestamp(state_attr('script.hallway_press_twice', 'last_triggered')) < (as_timestamp(now()) - as_timestamp('1970-01-01T' + states('input_datetime.airwick_hallway_status_sleep_interval') + 'Z')) }}"
sequence:
- service: script.hallway_press_twice
The script used in the automation:
hallway_press_twice:
alias: hallway - Press twice
mode: restart
sequence:
- service: switch.turn_on
data:
entity_id:
- switch.airwick_hallway_switch
The Input Datetimes:
airwick_hallway_status_home_interval:
name: AirWick hallway - Home Interval
icon: mdi:home
has_date: false
has_time: true
airwick_hallway_status_away_interval:
name: AirWick hallway - Away Interval
icon: mdi:home-import-outline
has_date: false
has_time: true
airwick_hallway_status_sleep_interval:
name: AirWick hallway - Sleep Interval
icon: mdi:sleep
has_date: false
has_time: true
The automation tries to trigger once per minute, if any of the conditions are met. Description for the automation conditions:
The panel shows the last time the script was triggered and also contains a button for manually triggering the script (it don't have any conditions, therefore you can push it as many times as you wish the AirWick to run)
Configuration for the panel:
type: vertical-stack
title: AirWick hallway
cards:
- type: custom:time-picker-card
entity: input_datetime.airwick_hallway_status_home_interval
hour_mode: 24
hour_step: 1
minute_step: 5
second_step: 5
name: Someone home
layout:
embedded: true
align_controls: right
name: header
- type: custom:time-picker-card
entity: input_datetime.airwick_hallway_status_sleep_interval
hour_mode: 24
hour_step: 1
minute_step: 5
second_step: 5
name: Everyone asleep
layout:
embedded: true
name: header
align_controls: right
- type: custom:time-picker-card
entity: input_datetime.airwick_hallway_status_away_interval
hour_mode: 24
hour_step: 1
minute_step: 5
second_step: 5
name: No one home
layout:
embedded: true
name: header
align_controls: right
- type: custom:multiple-entity-row
entity: script.hallway_press_twice
icon: mdi:air-horn
name: Last time sprayed
secondary_info:
attribute: last_triggered
format: relative
- type: button
tap_action:
action: toggle
entity: script.hallway_press_twice
name: Suihkauta nyt
show_state: false
icon_height: 48px
icon: mdi:air-horn
James CallaghanThis project is one that makes me feel on top of the world but also possibly one of my most craziest IoT projects. I am fascinated with IoT and the point where software interacts with my physical w…
What air freshener did you use?
Hi there,
I am working on a simular project to your esphome IOT Air Freshener ..I am sort of merging your project and another project (https://www.instructables.com/IoT-Air-Freshner-with-NodeMCU-Arduino-IFTTT-and-Ad/) into one and I am having a real hard time to get my esp code to work ...I like to use esp32 for projects but have 1 or 2 esp8266 around which I am trying now ..
But I was hoping to get a look at your code to see where I might be going wrong ...
cheers Richard