GithubHelp home page GithubHelp logo

scent-a-tron's Introduction

Scent-a-Tron Project

ESPHome code for my 'Scent-a-Tron' Project

substitutions:
  room: your_room_name_here # Change to your Room
  
  bright_level: "0.1"  # Enter Bright Level
  dark_level: "1.0"    # Enter Dark Level

globals:
  - id: sprays
    type: float
    restore_value: yes
    initial_value: "0"

esphome:
  name: freshmatic_${room}
  platform: ESP8266
  board: d1_mini

  ## Change your Wi-Fi Details here ##
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

logger:
  logs:
    adc: none
    sensor: none
    light: none
api:
ota:

binary_sensor:
  - platform: gpio
    id: reset
    pin: D4
    filters:
      - invert:
    on_press:
      then:
        - light.turn_on:
            id: led
            effect: flashfast
        - delay: 1s
        - light.turn_off: led
    on_release:
        - light.turn_off: led
    on_click:
      min_length: 900ms
      max_length: 3000ms
      then:
        - lambda: |-
            id(sprays) = 0;

sensor:
  - platform: template
    id: ${room}_can_level
    name: Freshmatic ${room} %
    device_class: pressure
    unit_of_measurement: "Can"
    update_interval: 1s
    lambda: |-
      return ( (2500-id(sprays) )/2500 ) * 100;

  - platform: homeassistant
    entity_id: input_select.freshmatic_${room}
    id: selector
    on_value:
      - if:
          condition:
            - switch.is_on: enable
            - lambda: "return id(selector).state > 1;"
          then:
            - switch.turn_on: spray

  - platform: adc
    id: ${room}_brightness
    pin: A0
    name: Freshmatic ${room} Lux
    update_interval: 2s
    device_class: illuminance
    unit_of_measurement: lx
    
    ### -- Un-Comment these after Calibrating -- ###
    filters:
      # - calibrate_linear:
      #     - ${bright_level} -> 1.0
      #     - ${dark_level} -> 0.0
      # - multiply: 100
    ### -------------[ Use Ctrl+? ]------------- ###
    
    on_value:
      - if:
          condition:
            for:
              time: 20000s
              condition:
                and:
                  - lambda: "return id(${room}_brightness).state < 10;"
                  - switch.is_off: its_dark
          then:
            - switch.turn_on: its_dark
      - if:
          condition:
            and:
              - lambda: "return id(${room}_brightness).state > 10;"
              - switch.is_on: enable
              - lambda: "return id(selector).state < 1;"
              - switch.is_on: its_dark
          then:
            - switch.turn_on: spray
            - delay: 5s
            - switch.turn_off: its_dark

switch:
  - platform: gpio
    name: Freshmatic ${room} Spray
    id: spray
    icon: mdi:spray
    pin: D2
    on_turn_on:
      - light.turn_on: led
      - switch.turn_on: timer
      - delay: 0.25s
      - switch.turn_off: spray
      - lambda: |-
          id(sprays) += 1;

  - platform: template
    id: enable
    name: Freshmatic ${room} Enable
    optimistic: true
    on_turn_on:
      - switch.turn_on: timer

  - platform: template
    id: its_dark
    icon: mdi:brightness-4
    optimistic: true

  - platform: template
    id: timer
    optimistic: true
    on_turn_on:
      - delay: !lambda return id(selector).state* (60000);
      - switch.turn_off: timer
      - if:
          condition:
            - switch.is_on: enable
            - lambda: "return id(selector).state > 1;"
          then:
            - light.turn_on:
                id: led
                effect: pulse
            - delay: 1.0s
            - light.turn_off: led
            - switch.turn_on: spray

light:
  - platform: monochromatic
    output: out_led
    default_transition_length: 0s
    id: led
    effects:
      - pulse:
          transition_length: 0.0s
          update_interval: 0.05s
      - pulse:
          name: flashfast
          transition_length: 0.0s
          update_interval: 0.025s
    on_turn_on:
      - delay: 2s
      - light.turn_off: led

output:
  platform: esp8266_pwm
  pin:
    number: D3
    inverted: true
  id: out_led

πŸ’– Found this useful, want to say 'Thanks' and support my efforts. CHEERS🍺

Buy me a Coffee PATREON
https://www.buymeacoffee.com/3ative https://www.patreon.com/3ative

scent-a-tron's People

Contributors

3ative avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.