Setting-up Home Assistant

From Eric

Revision as of 11:34, 15 July 2022 by Ejenn (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Discovery

  • For devices to be automatically discovered by Home Assistant, their configuration must be published as shown below (for an ESP32 Arduino platform):
  Serial.println("Sending discovery data: ");
  client.publish("homeassistant/sensor/mto1_t1/config", 
    "{\"unique_id\": \"mto1_t1\", \"dev_cla\": \"temperature\", \"name\": \"mto1_t1\", \"stat_t\": \"tele/lorabridge/mto1\", \"unit_of_meas\": \"°C\", \"val_tpl\": \"Template:Value json.t1\"}" ) ;   
  client.publish("homeassistant/sensor/mto1_t2/config", 
    "{\"unique_id\": \"mto1_t2\", \"dev_cla\": \"temperature\", \"name\": \"mto1_t2\", \"stat_t\": \"tele/lorabridge/mto1\", \"unit_of_meas\": \"°C\", \"val_tpl\": \"Template:Value json.t2\"}" ) ;          
  client.publish("homeassistant/sensor/mto1_h/config", 
    "{\"unique_id\": \"mto1_h\", \"dev_cla\": \"humidity\", \"name\": \"mto1_h\", \"stat_t\": \"tele/lorabridge/mto1\", \"unit_of_meas\": \"%\", \"val_tpl\": \"Template:Value json.h\"}" ) ;     
  client.publish("homeassistant/sensor/mto1_p/config", 
    "{\"unique_id\": \"mto1_p\", \"dev_cla\": \"pressure\", \"name\": \"mto1_p\", \"stat_t\": \"tele/lorabridge/mto1\", \"unit_of_meas\": \"Pa\", \"val_tpl\": \"Template:Value json.p\"}" ) ;
  client.publish("homeassistant/sensor/mto1_a/config", 
    "{\"unique_id\": \"mto1_a\", \"name\": \"mto1_a\", \"stat_t\": \"tele/lorabridge/mto1\", \"unit_of_meas\": \"m\", \"val_tpl\": \"Template:Value json.a\"}" ) ;
  client.publish("homeassistant/sensor/mto1_vbat/config", 
    "{\"unique_id\": \"mto1_vbat\", \"name\": \"mto1_vbat\", \"stat_t\": \"tele/lorabridge/mto1\", \"unit_of_meas\": \"V\", \"val_tpl\": \"Template:Value json.vbat\"}" ) ;}

The corresponding JSON message for the pressure is the following: {"unique_id": "mto1_p", "dev_cla": "pressure", "name": "mto1_p", "stat_t": "tele/lorabridge/mto1", "unit_of_meas": "Pa", "val_tpl": "Template:Value json.p"}

Here, I have used the abbreviated attributes names.


EspHome

The display

The display box incorporates a DFPlayer chip (with its amplifier) and a rotary switch. The ESPHome configuration file is the following:

esphome:
 name: esp32dsp1
 platform: ESP32
 board: nodemcu-32s

# Enable logging
logger:

ota:
 password: "zorglub_1"

wifi:
 ssid: "edvac"
 password: "ae03f5ab16"
 manual_ip:
  static_ip: 192.168.0.43
  gateway: 192.168.0.254
  subnet: 255.255.255.0
 
output:
  - platform: ledc
    pin: 32
    id: gpio_32_backlight_pwm
  - platform: gpio
    pin: 32
    id: gpio_backlight_off
    inverted: yes

light:
  - platform: monochromatic
    output: gpio_32_backlight_pwm
    name: "ILI9341 Display Backlight"
    id: back_light
    restore_mode: ALWAYS_OFF
    on_turn_off:
      then:
        - delay: 10s
        - light.turn_on:
            id: back_light

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO19


font:
  - file: "fonts/comicsansms.ttf"
    id: my_font
    size: 20
    
color:
  - id: my_red
    red: 100%
    green: 3%
    blue: 5%

time:
  - platform: homeassistant
    id: homeassistant_time

display:
 - platform: ili9341
   model: TFT 2.4
   cs_pin: 21
   dc_pin: 27
   led_pin: 32
   reset_pin: 33
   id: tft_ha
   rotation: 180
   lambda: |-
    it.fill(COLOR_BLACK);
    // Print time in HH:MM format
    it.strftime(0, 0, id(my_font), "%H:%M", id(homeassistant_time).now());
    it.printf(0, 21, id(my_font), id(my_red), "Temp Eric: %s", id(temp_eric).state.c_str());
    it.printf(0, 42, id(my_font), id(my_red), "Temp living: %s", id(temp_living).state.c_str());
    it.printf(0, 63, id(my_font), id(my_red), "Temp lab: %s", id(temp_lab).state.c_str());

# Example configuration entry
sensor:
  - platform: rotary_encoder
    name: "dsp rot enc"
    pin_a: 34
    pin_b: 35
    on_clockwise:
    - logger.log: "Turned Clockwise"
    on_anticlockwise:
    - logger.log: "Turned Anticlockwise"
    publish_initial_value: true

binary_sensor:
  - platform: gpio
    pin: 
      number: 25
      mode:
        input: true
        pullup: true    
    name: "dsp_button"
    device_class: window

text_sensor:
  - platform: homeassistant
    entity_id: sensor.0x00124b00226994c4_temperature
    name: "Temp. Eric"
    id: temp_eric
  - platform: homeassistant
    entity_id: sensor.0x00124b0022ebf1ff_temperature
    name: "Temp. living"
    id: temp_living
  - platform: homeassistant
    entity_id: sensor.0x00124b0022697fe1_temperature
    name: "Temp. lab"
    id: temp_lab

uart:
  tx_pin: 17
  rx_pin: 16
  baud_rate: 9600

# Declare DFPlayer mini module
dfplayer:
  on_finished_playback:
    then:
      logger.log: 'Somebody press play!'
# Enable Home Assistant API
api:
 password: "zorglub_1"
 services:
 - service: dfplayer_next
   then:
     - dfplayer.play_next:
 - service: dfplayer_previous
   then:
     - dfplayer.play_previous:
 - service: dfplayer_play
   variables:
     file: int
   then:
     - dfplayer.play: !lambda 'return file;'
 - service: dfplayer_play_loop
   variables:
     file: int
     loop_: bool
   then:
     - dfplayer.play:
         file: !lambda 'return file;'
         loop: !lambda 'return loop_;'

 - service: dfplayer_set_volume
   variables:
     volume: int
   then:
     - dfplayer.set_volume: !lambda 'return volume;'
      
 - service: dfplayer_set_eq
   variables:
     preset: int
   then:
     - dfplayer.set_eq: !lambda 'return static_cast<dfplayer::EqPreset>(preset);'
  
 - service: dfplayer_sleep
   then:
     - dfplayer.sleep
 
 - service: dfplayer_reset
   then:
     - dfplayer.reset
  
 - service: dfplayer_volume_up
   then:
     - dfplayer.volume_up
  
 - service: dfplayer_volume_down
   then:
     - dfplayer.volume_down



Node Red

Node Red for RF switches

Node Red for Ikea switches

Personal tools