El de las barras con boot sequence

mail@pastecode.io avatar
unknown
plain_text
2 years ago
12 kB
1
Indexable
Never
esphome:
  name: d1-pullup-2000
  on_boot: 
    then:
      - script.execute: displayblank
      - switch.turn_on: SN74HC595pH
      - wait_until:
          wifi.connected:
      - rtttl.play: 'scale_up:d=32,o=5,b=100:c,c#,d#,e,f#,g#,a#,b'
      - logger.log: "******Se supone que sonó welcome tone?********"
      - script.execute: displayblank

esp8266:
  board: d1_mini
#########################################

time:
  - platform: homeassistant
    id: homeassistant_time
    on_time:
      # Cron syntax, trigger every day minutes
      - seconds: 0
        minutes: 0
        hours: 0
        then:
          - script.execute: reset_pullup_ct
          
script:
  - id: increase_pullup_ct
    then:
      - lambda: "id(g_counter) = id(g_counter) + 1;"
      - component.update: pullup_count
      - logger.log: "******Counter +1********"
      - rtttl.play: 'two short:d=4,o=5,b=100:16e6,16e7'
      - delay: 2s
      - switch.turn_off: SN74HC595pH
  - id: decrease_pullup_ct
    then:
      - lambda: "id(g_counter) = id(g_counter) - 1;"
      - component.update: pullup_count
      - logger.log: "******Counter -1********"
      - rtttl.play: 'two short:d=4,o=5,b=100:16e7,16e6,16e5'
      - delay: 1s
  - id: reset_pullup_ct
    then:
      - lambda: "id(g_counter) = 0;"
      - component.update: pullup_count
      - logger.log:  "******Counter =0********"
      - script.execute: displayblank
      - rtttl.play: 'long:d=2,o=5,b=100:e6'

  #7 segment display
  - id: displayblank
    then:
      - switch.turn_off: SN74HC595pA
      - switch.turn_off: SN74HC595pB
      - switch.turn_off: SN74HC595pC
      - switch.turn_off: SN74HC595pD
      - switch.turn_off: SN74HC595pE
      - switch.turn_off: SN74HC595pF
      - switch.turn_off: SN74HC595pG
      - switch.turn_off: SN74HC595pH
  - id: display1
    then:
      - switch.turn_off: SN74HC595pA
      - switch.turn_on: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_off: SN74HC595pD
      - switch.turn_off: SN74HC595pE
      - switch.turn_off: SN74HC595pF
      - switch.turn_off: SN74HC595pG
  - id: display2
    then:
      - switch.turn_on: SN74HC595pA
      - switch.turn_on: SN74HC595pB
      - switch.turn_off: SN74HC595pC
      - switch.turn_on: SN74HC595pD
      - switch.turn_on: SN74HC595pE
      - switch.turn_off: SN74HC595pF
      - switch.turn_on: SN74HC595pG
  - id: display3
    then:
      - switch.turn_on: SN74HC595pA
      - switch.turn_on: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_on: SN74HC595pD
      - switch.turn_off: SN74HC595pE
      - switch.turn_off: SN74HC595pF
      - switch.turn_on: SN74HC595pG
  - id: display4
    then:
      - switch.turn_off: SN74HC595pA
      - switch.turn_on: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_off: SN74HC595pD
      - switch.turn_off: SN74HC595pE
      - switch.turn_on: SN74HC595pF
      - switch.turn_on: SN74HC595pG
  - id: display5
    then:
      - switch.turn_on: SN74HC595pA
      - switch.turn_off: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_on: SN74HC595pD
      - switch.turn_off: SN74HC595pE
      - switch.turn_on: SN74HC595pF
      - switch.turn_on: SN74HC595pG
  - id: display6
    then:
      - switch.turn_on: SN74HC595pA
      - switch.turn_off: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_on: SN74HC595pD
      - switch.turn_on: SN74HC595pE
      - switch.turn_on: SN74HC595pF
      - switch.turn_on: SN74HC595pG
  - id: display7
    then:
      - switch.turn_on: SN74HC595pA
      - switch.turn_on: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_off: SN74HC595pD
      - switch.turn_off: SN74HC595pE
      - switch.turn_off: SN74HC595pF
      - switch.turn_off: SN74HC595pG
  - id: display8
    then:
      - switch.turn_on: SN74HC595pA
      - switch.turn_on: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_on: SN74HC595pD
      - switch.turn_on: SN74HC595pE
      - switch.turn_on: SN74HC595pF
      - switch.turn_on: SN74HC595pG
  - id: display9
    then:
      - switch.turn_on: SN74HC595pA
      - switch.turn_on: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_on: SN74HC595pD
      - switch.turn_off: SN74HC595pE
      - switch.turn_on: SN74HC595pF
      - switch.turn_on: SN74HC595pG
  - id: displayd
    then:
      - switch.turn_off: SN74HC595pA
      - switch.turn_on: SN74HC595pB
      - switch.turn_on: SN74HC595pC
      - switch.turn_on: SN74HC595pD
      - switch.turn_on: SN74HC595pE
      - switch.turn_off: SN74HC595pF
      - switch.turn_on: SN74HC595pG

globals:
  - id: g_counter 
    type: uint32 
    initial_value: '0'
  - id: over_nine_counter 
    type: bool 
    initial_value: 'false'

binary_sensor:
  - platform: gpio
    pin:
      number: D4
      mode:
        input: true
        pullup: true
    id: global_resetter_button
    internal: true
    on_press:
      then:
        - logger.log: "************Reset button pressed************"
        - script.execute: reset_pullup_ct

  - platform: gpio
    pin:
      number: D2
      mode:
        input: true
        pullup: true
    id: diminish_button
    internal: true
    on_press:
      then:
        - logger.log: "************Substract button pressed************"
        - script.execute: decrease_pullup_ct
     
sensor:
  - platform: template 
    name: Pullup Count 
    id: pullup_count 
    unit_of_measurement: pullups
    update_interval: never 
    lambda: "return id(g_counter);"
    on_value:
      then:
        - if:
            condition:
              lambda: 'return (id(g_counter) == 1);'
            then:
              - script.execute: display1
        - if:
            condition:
              lambda: 'return (id(g_counter) == 2);'
            then:
              - script.execute: display2
        - if:
            condition:
              lambda: 'return (id(g_counter) == 3);'
            then:
              - script.execute: display3
        - if:
            condition:
              lambda: 'return (id(g_counter) == 4);'
            then:
              - script.execute: display4
        - if:
            condition:
              lambda: 'return (id(g_counter) == 5);'
            then:
              - script.execute: display5
        - if:
            condition:
              lambda: 'return (id(g_counter) == 6);'
            then:
              - script.execute: display6
        - if:
            condition:
              lambda: 'return (id(g_counter) == 7);'
            then:
              - script.execute: display7
        - if:
            condition:
              lambda: 'return (id(g_counter) == 8);'
            then:
              - script.execute: display8
        - if:
            condition:
              lambda: 'return (id(g_counter) == 9);'
            then:
              - script.execute: display9
        - if:
            condition:
              lambda: 'return (id(g_counter) == 10);'
            then:
              - script.execute: displayd
              - rtttl.play: 'MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d'
              - logger.log: "************>9 pullups!************"
      
            

  - platform: ultrasonic
    trigger_pin: D0
    echo_pin: D5
    id: pullup_head_distance_id
    update_interval: 100ms
    unit_of_measurement: "cm"
    filters:
      # - lambda: return if(isnan(x)) {return 1.0} else {return x}; # * (9.0/5.0) + 32.0;
      
      - lambda: !lambda |-
          if (isnan(x)) {
            return 1.0;
          } else {
            return x;
          }
      - multiply: 100
    on_value_range:
      below: 50
      then:
        - logger.log: "************Pullup registered************"
        - switch.turn_on: SN74HC595pH
        - script.execute: increase_pullup_ct
        
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 1);'
        #     then:
        #       - script.execute: display1
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 2);'
        #     then:
        #       - script.execute: display2
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 3);'
        #     then:
        #       - script.execute: display3
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 4);'
        #     then:
        #       - script.execute: display4
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 5);'
        #     then:
        #       - script.execute: display5
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 6);'
        #     then:
        #       - script.execute: display6
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 7);'
        #     then:
        #       - script.execute: display7
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 8);'
        #     then:
        #       - script.execute: display8
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 9);'
        #     then:
        #       - script.execute: display9
        # - if:
        #     condition:
        #       lambda: 'return (id(g_counter) == 10);'
        #     then:
        #       - script.execute: displayd
        #       - rtttl.play: 'MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d'
        #       - logger.log: "************>9 pullups!************"
            
        

output:
  - platform: esp8266_pwm
    pin: D1
    id: rtttl_out

###995###
sn74hc595:
  - id: 'sn74hc595_hub'
    data_pin: D6
    clock_pin: D7
    latch_pin: D8
    # oe_pin: D6
    sr_count: 1

# Individual outputs
switch:
  - platform: gpio
    id: "SN74HC595pA"
    pin:
      sn74hc595: sn74hc595_hub
      number: 0
      inverted: false
  - platform: gpio
    id: "SN74HC595pB"
    pin:
      sn74hc595: sn74hc595_hub
      number: 1
      inverted: false
  - platform: gpio
    id: "SN74HC595pC"
    pin:
      sn74hc595: sn74hc595_hub
      number: 2
      inverted: false
  - platform: gpio
    id: "SN74HC595pD"
    pin:
      sn74hc595: sn74hc595_hub
      number: 3
      inverted: false
  - platform: gpio
    id: "SN74HC595pE"
    pin:
      sn74hc595: sn74hc595_hub
      number: 4
      inverted: false
  - platform: gpio
    id: "SN74HC595pF"
    pin:
      sn74hc595: sn74hc595_hub
      number: 5
      inverted: false
  - platform: gpio
    id: "SN74HC595pG"
    pin:
      sn74hc595: sn74hc595_hub
      number: 6
      inverted: false
  - platform: gpio
    id: "SN74HC595pH"
    pin:
      sn74hc595: sn74hc595_hub
      number: 7
      inverted: false
###995###


rtttl:
  output: rtttl_out        

# Enable logging
logger:
  level: DEBUG
  logs:
    ultrasonic.sensor: INFO
    sensor: INFO
    
    

# Enable Home Assistant API
api:

ota:
  password: "54bb50822cd339044f0521f0a42b592d"

wifi:
  ssid: Little Radish
  password: delita28
  manual_ip:
    static_ip: 192.168.1.34
    gateway: 192.168.1.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "D1-Pullup-2000 Fallback Hotspot"
    password: "perreusmaximusextremus"

captive_portal: