packages: - !include common/wifi.yaml - !include common/canbus.yaml substitutions: name: sthome-ut3 friendly_name: "sthome-ut3" v_ON: "{ 0x4F,0x4E }" v_OFF: "{ 0x4F, 0x46, 0x46 }" esphome: name: "${name}" friendly_name: "${friendly_name}" globals: - id: geyser_relay_status type: bool restore_value: yes initial_value: 'false' esp32: board: nodemcu-32s #esp32dev framework: type: arduino # Example configuration entry #debug: # update_interval: 5s # Enable logging logger: level: verbose # Enable Home Assistant API api: encryption: key: "AIoquKPjpcHa2pcJ0aKxvtpM3mwgZuZhpCPtdVitP2Q=" ota: - platform: esphome password: "879012af7180c8700cee65fbf18704d1" wifi: manual_ip: static_ip: 10.0.2.3 # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "${name} Fallback Hotspot" password: "cGXb2DqkwaOr" captive_portal: sun: id: sun_sensor latitude: !secret latitude longitude: !secret longitude time: - platform: homeassistant id: time_source update_interval: 360min # Change sync interval from default 5min to 6 hours on_time_sync: then: - if: # Publish the time the device was last restarted, but only once. condition: lambda: 'return id(device_last_restart).state == "";' then: - text_sensor.template.publish: id: device_last_restart state: !lambda 'return id(time_source).now().strftime("%a %d %b %Y - %I:%M:%S %p");' interval: - interval: 30s then: - if: condition: lambda: 'return !isnan(id(geyser_top_temperature).raw_state);' then: - canbus.send: canbus_id: canbus_sthome can_id: ${CB_GEYSER_TOP_TEMPERATURE} data: !lambda |- double temp = id(geyser_top_temperature).raw_state; int value = (int) (temp * 16777216); std::vector byte_stream(sizeof(value)); memcpy(byte_stream.data(), &value, sizeof(value)); ESP_LOGI("SND:${CB_GEYSER_TOP_TEMPERATURE}", "Geyser TOP temp: %d (%f)", value, temp); //ESP_LOGI("SND:0x400", "Geyser TOP temp: %f, x3: %d, x2: %d, x1: %d, x0: %d, xSize: %d", temp, byte_stream[3],byte_stream[2], byte_stream[1], byte_stream[0], byte_stream.size()); return byte_stream; - delay: 1s - if: condition: lambda: 'return !isnan(id(geyser_bottom_temperature).raw_state);' then: - canbus.send: canbus_id: canbus_sthome can_id: ${CB_GEYSER_BOTTOM_TEMPERATURE} data: !lambda |- double temp = id(geyser_bottom_temperature).raw_state; int value = (int) (temp * 16777216); std::vector byte_stream(sizeof(value)); memcpy(byte_stream.data(), &value, sizeof(value)); ESP_LOGI("SND:${CB_GEYSER_BOTTOM_TEMPERATURE}", "Geyser BOTTOM temp: %d (%f)", value, temp); //ESP_LOGI("SND:0x401", "Geyser BOTTOM temp: %f", temp, byte_stream[3],byte_stream[2], byte_stream[1], byte_stream[0], byte_stream.size()); return byte_stream; - delay: 1s - canbus.send: canbus_id: canbus_sthome can_id: ${CB_GEYSER_ENERGISED} data: !lambda |- if (id(geyser_heating).state) { std::vector byte_stream = ${v_ON}; ESP_LOGI("SND:${CB_GEYSER_ENERGISED}", "Geyser state: %c%c", byte_stream[0], byte_stream[1]); return byte_stream; } else { std::vector byte_stream = ${v_OFF}; ESP_LOGI("SND:${CB_GEYSER_ENERGISED}", "Geyser state: %c%c%c", byte_stream[0], byte_stream[1], byte_stream[2]); return byte_stream; } - interval: 10s then: - canbus.send: canbus_id: canbus_sthome data: [0x48, 0x45, 0x4C, 0x4C, 0x4F] - lambda: |- ESP_LOGI("SND:${CB_CANBUS_ID3}", "HELLO"); spi: - id: spi_bus0 clk_pin: GPIO18 mosi_pin: GPIO23 miso_pin: GPIO19 interface: any # CAN BUS canbus: - platform: mcp2515 cs_pin: GPIO16 spi_id: spi_bus0 mode: NORMAL id: canbus_sthome can_id: ${CB_CANBUS_ID3} bit_rate: 500KBPS #20KBPS on_frame: # - can_id: 0 # can_id_mask: 0 # then: # - logger.log: # format: "ID: 0x%03X -> %s" # args: [ id, x ] # tag: "canbus" - can_id: 0 can_id_mask: 0 then: - lambda: |- std::string b(x.begin(), x.end()); ESP_LOGI("REC: 0", "%s", &b[0] ); //ESP_LOGI("canbus", "REC: ID: %d, data: %s, rtr: %s", // x.can_id, // x.data.c_str(), // x.remote_transmission_request ? "true" : "false"); # - can_id: ${CB_CANBUS_ID1} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID1}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID2} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID2}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID3} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID3}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID4} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID4}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID5} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID5}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID6} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID6}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID7} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID7}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID8} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID8}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID9} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID9}", "%s", &b[0] ); # - can_id: ${CB_CANBUS_ID10} # then: # - lambda: |- # std::string b(x.begin(), x.end()); # ESP_LOGI("REC:${CB_CANBUS_ID10}", "%s", &b[0] ); # Define a PWM output on the ESP32 output: - platform: ledc pin: GPIO26 id: backlight_pwm # Define a monochromatic, dimmable light for the backlight light: - platform: monochromatic output: backlight_pwm name: "Display Backlight" id: back_light restore_mode: ALWAYS_ON switch: - platform: restart name: "${name} Restart" id: "restart_switch" binary_sensor: - platform: homeassistant name: "Geyser Heating" entity_id: binary_sensor.sthome_ut8_heating id: geyser_heating on_press: then: - canbus.send: canbus_id: canbus_sthome can_id: ${CB_GEYSER_ENERGISED} data: !lambda |- std::vector byte_stream = ${v_ON}; ESP_LOGI("SND:${CB_GEYSER_ENERGISED}", "Geyser state: %c%c", byte_stream[0], byte_stream[1]); return byte_stream; on_release: then: - canbus.send: canbus_id: canbus_sthome can_id: ${CB_GEYSER_ENERGISED} data: !lambda |- std::vector byte_stream = ${v_OFF}; ESP_LOGI("SND:${CB_GEYSER_ENERGISED}", "Geyser state: %c%c%c", byte_stream[0], byte_stream[1], byte_stream[2]); return byte_stream; sensor: - platform: homeassistant name: "Geyser Top Temperature" entity_id: sensor.sthome_ut8_geyser_top_temperature id: geyser_top_temperature on_raw_value: then: - canbus.send: canbus_id: canbus_sthome can_id: ${CB_GEYSER_TOP_TEMPERATURE} data: !lambda |- double temp = id(geyser_top_temperature).raw_state; int value = (int) (temp * 16777216); std::vector byte_stream(sizeof(value)); memcpy(byte_stream.data(), &value, sizeof(value)); ESP_LOGI("SND:${CB_GEYSER_TOP_TEMPERATURE}", "Geyser TOP temp: %d (%f)", value, temp); //ESP_LOGI("SND:0x400", "Geyser TOP temp: %f, x3: %d, x2: %d, x1: %d, x0: %d, xSize: %d", temp, byte_stream[3],byte_stream[2], byte_stream[1], byte_stream[0], byte_stream.size()); return byte_stream; - platform: homeassistant name: "Geyser Bottom Temperature" entity_id: sensor.sthome_ut8_geyser_bottom_temperature id: geyser_bottom_temperature on_raw_value: then: - canbus.send: canbus_id: canbus_sthome can_id: ${CB_GEYSER_BOTTOM_TEMPERATURE} data: !lambda |- double temp = id(geyser_bottom_temperature).raw_state; int value = (int) (temp * 16777216); std::vector byte_stream(sizeof(value)); memcpy(byte_stream.data(), &value, sizeof(value)); ESP_LOGI("SND:${CB_GEYSER_BOTTOM_TEMPERATURE}", "Geyser BOTTOM temp: %d (%f)", value, temp); //ESP_LOGI("SND:0x401", "Geyser BOTTOM temp: %f", temp, byte_stream[3],byte_stream[2], byte_stream[1], byte_stream[0], byte_stream.size()); return byte_stream; # Report wifi signal strength every 5 min if changed - platform: wifi_signal name: WiFi Signal id: wifi_sig update_interval: 300s filters: - delta: 10% text_sensor: # - platform: template # id: module_time # name: "Module time" # icon: mdi:clock # lambda: |- # auto time_obj = id(time_source).now(); # return time_obj.strftime("%Y-%m-%d %H:%M:%S"); # update_interval: 60s # Expose WiFi information as sensors - platform: wifi_info ip_address: name: IP update_interval: 10s mac_address: name: Mac Address entity_category: diagnostic ssid: name: "Connected SSID" id: ssid entity_category: diagnostic # human readable update text sensor from sensor:uptime - platform: template name: Uptime id: uptime_human icon: mdi:clock-start - platform: template name: 'Last Restart' id: device_last_restart icon: mdi:clock entity_category: diagnostic