diff --git a/configuration.yaml b/configuration.yaml index ffbfc3f..75a7c89 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -8,6 +8,7 @@ homeassistant: customize: !include customize.yaml packages: !include_dir_named packages +template: !include_dir_merge_list templates #group: !include groups.yaml group: !include_dir_merge_named group/ automation: !include_dir_merge_list automations/ @@ -44,7 +45,7 @@ zha: ledvance_provider: true salus_provider: true inovelli_provider: true - thirdreality_provider: true + thirdreality_provider: true device_tracker: - platform: bluetooth_le_tracker diff --git a/esphome/common/mqtt_common.yaml b/esphome/common/mqtt_common.yaml index 43994a9..0211701 100644 --- a/esphome/common/mqtt_common.yaml +++ b/esphome/common/mqtt_common.yaml @@ -14,7 +14,7 @@ substitutions: ############################################# mqtt: broker: ${mqtt_server} - topic_prefix: ${mqtt_topic}/${device_name} + topic_prefix: ${mqtt_topic}/${local_device_name} username: ${mqtt_username} password: ${mqtt_password} discovery: False # enable entity discovery (true is default) diff --git a/esphome/common/network_common.yaml b/esphome/common/network_common.yaml index bb7eb0a..5395de0 100644 --- a/esphome/common/network_common.yaml +++ b/esphome/common/network_common.yaml @@ -23,7 +23,12 @@ substitutions: # Add these if we are giving it a static ip, or remove them in the Wifi section static_ip_subnet: !secret ha_wifi_subnet static_ip_gateway: !secret ha_wifi_gateway - static_ip_dns1: !secret ha_wifi_gateway + static_ip_dns1: !secret ha_wifi_dns1 + static_ip_dns2: !secret ha_wifi_dns2 + + # Network reconnect every x hours to ensure best access point + base_interval_hours: "6" # Base interval in hours + random_offset_max_minutes: "59" # Max random offset in minutes ############################################# # Common Wifi Settings @@ -45,8 +50,9 @@ wifi: gateway: ${static_ip_gateway} subnet: ${static_ip_subnet} dns1: ${static_ip_dns1} + dns2: ${static_ip_dns2} ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode - ssid: ${device_name} AP + ssid: ${local_device_name} AP password: ${fallback_ap_password} ap_timeout: 10min # Time until it brings up fallback AP. default is 1min # Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID @@ -78,4 +84,37 @@ safe_mode: # https://esphome.io/components/network.html ############################################# network: - enable_ipv6: ${ipv6_enable} \ No newline at end of file + enable_ipv6: ${ipv6_enable} + +############################################# +# Interval +# Restart Networking every x hours + rand mins +# This ensure that the device is connected to the best AP +############################################# +script: + - id: random_reconnect + mode: restart + then: + - lambda: |- + // Compute total delay: base hours + random offset minutes + uint32_t extra; + #if defined(ESP32) + // ESP32 (both Arduino & IDF builds) uses esp_random() + extra = esp_random() % (${random_offset_max_minutes} + 1); + #elif defined(ESP8266) + // ESP8266 Arduino core + extra = os_random() % (${random_offset_max_minutes} + 1); + #else + // Fallback to esp_random() on other platforms + extra = esp_random() % (${random_offset_max_minutes} + 1); + #endif + uint32_t total_s = ${base_interval_hours} * 3600 + extra * 60; + ESP_LOGI("random_reconnect", "Next reconnect in %u seconds", total_s); + // Delay inside lambda (blocks script execution but OK for reconnect timing) + delay(total_s * 1000); + - logger.log: "network_check: performing reconnect" + - wifi.disable: {} + - delay: 1s + - wifi.enable: {} + - script.execute: random_reconnect + diff --git a/esphome/common/network_common_dual.yaml b/esphome/common/network_common_dual.yaml new file mode 100644 index 0000000..5003a71 --- /dev/null +++ b/esphome/common/network_common_dual.yaml @@ -0,0 +1,126 @@ +substitutions: + ############################################## + # SPECIFIC DEVICE VARIABLE SUBSTITUTIONS + # If NOT using a secrets file, just replace these with the passwords etc (in quotes) + ############################################# + wifi_ssid: !secret ha_wifi_ssid + wifi_password: !secret ha_wifi_password + fallback_ap_password: !secret fallback_ap_password + + # Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken + wifi_fast_connect: "false" + + # Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs) + dns_domain: ".local" + + # Automatically add the mac address to the name + # eg so you can use a single firmware for all devices + add_mac_suffix: "false" + + # Enable or disable the use of IPv6 networking on the device + ipv6_enable: "false" + + # Add these if we are giving it a static ip, or remove them in the Wifi section + static_ip_subnet: !secret ha_wifi_subnet + static_ip_gateway: !secret ha_wifi_gateway + static_ip_dns1: !secret ha_wifi_dns1 + static_ip_dns2: !secret ha_wifi_dns2 + + # Network reconnect every x hours to ensure best access point + base_interval_hours: "6" # Base interval in hours + random_offset_max_minutes: "59" # Max random offset in minutes + +############################################# +# Common Wifi Settings +# https://esphome.io/components/wifi.html +# +# Power Save mode (can reduce wifi reliability) +# NONE (least power saving, Default for ESP8266) +# LIGHT (Default for ESP32) +# HIGH (most power saving) +############################################# +wifi: + networks: + - ssid: "vega_control_1" + password: "3Kd#vQBP8RDc" + priority: 1.0 + - ssid: ${wifi_ssid} + password: ${wifi_password} + #enable_rrm: true # (ESP32 only) enable 802.11k Radio Resource Management + #enable_btm: true # (ESP32 only) enable 802.11v BSS Transition Management + #power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode + priority: 0.5 + manual_ip: # optional static IP address + static_ip: ${local_static_ip_address} + gateway: ${static_ip_gateway} + subnet: ${static_ip_subnet} + dns1: ${static_ip_dns1} + dns2: ${static_ip_dns2} + + use_address: ${local_static_ip_address} # required when any network uses manual_ip + ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode + ssid: ${device_name} AP + password: ${fallback_ap_password} + ap_timeout: 10min # Time until it brings up fallback AP. default is 1min + # Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID + fast_connect: "${wifi_fast_connect}" + # Define dns domain / suffix to add to hostname + domain: "${dns_domain}" + +#captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails + +############################################# +# Enable Over the Air Update Capability +# https://esphome.io/components/ota.html?highlight=ota +############################################# +ota: + - platform: esphome + password: ${local_ota_pass} + version: 2 + +############################################# +# Safe Mode +# Safe mode will detect boot loops +# https://esphome.io/components/safe_mode +############################################# +safe_mode: + +############################################# +# Network +# global configuration for all types of networks +# https://esphome.io/components/network.html +############################################# +network: + enable_ipv6: ${ipv6_enable} + +############################################# +# Interval +# Restart Networking every x hours + rand mins +############################################# +script: + - id: random_reconnect + mode: restart + then: + - lambda: |- + // Compute total delay: base hours + random offset minutes + uint32_t extra; + #if defined(ESP32) + // ESP32 (both Arduino & IDF builds) uses esp_random() + extra = esp_random() % (${random_offset_max_minutes} + 1); + #elif defined(ESP8266) + // ESP8266 Arduino core + extra = os_random() % (${random_offset_max_minutes} + 1); + #else + // Fallback to esp_random() on other platforms + extra = esp_random() % (${random_offset_max_minutes} + 1); + #endif + uint32_t total_s = ${base_interval_hours} * 3600 + extra * 60; + ESP_LOGI("random_reconnect", "Next reconnect in %u seconds", total_s); + // Delay inside lambda (blocks script execution but OK for reconnect timing) + delay(total_s * 1000); + - logger.log: "network_check: performing reconnect" + - wifi.disable: {} + - delay: 1s + - wifi.enable: {} + - script.execute: random_reconnect + diff --git a/esphome/common/network_common_fallback.yaml b/esphome/common/network_common_fallback.yaml new file mode 100644 index 0000000..bb7eb0a --- /dev/null +++ b/esphome/common/network_common_fallback.yaml @@ -0,0 +1,81 @@ +substitutions: + ############################################## + # SPECIFIC DEVICE VARIABLE SUBSTITUTIONS + # If NOT using a secrets file, just replace these with the passwords etc (in quotes) + ############################################# + wifi_ssid: !secret ha_wifi_ssid + wifi_password: !secret ha_wifi_password + fallback_ap_password: !secret fallback_ap_password + + # Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken + wifi_fast_connect: "false" + + # Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs) + dns_domain: ".local" + + # Automatically add the mac address to the name + # eg so you can use a single firmware for all devices + add_mac_suffix: "false" + + # Enable or disable the use of IPv6 networking on the device + ipv6_enable: "false" + + # Add these if we are giving it a static ip, or remove them in the Wifi section + static_ip_subnet: !secret ha_wifi_subnet + static_ip_gateway: !secret ha_wifi_gateway + static_ip_dns1: !secret ha_wifi_gateway + +############################################# +# Common Wifi Settings +# https://esphome.io/components/wifi.html +# +# Power Save mode (can reduce wifi reliability) +# NONE (least power saving, Default for ESP8266) +# LIGHT (Default for ESP32) +# HIGH (most power saving) +############################################# +wifi: + ssid: ${wifi_ssid} + password: ${wifi_password} + #enable_rrm: true # (ESP32 only) enable 802.11k Radio Resource Management + #enable_btm: true # (ESP32 only) enable 802.11v BSS Transition Management + #power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode + manual_ip: # optional static IP address + static_ip: ${local_static_ip_address} + gateway: ${static_ip_gateway} + subnet: ${static_ip_subnet} + dns1: ${static_ip_dns1} + ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode + ssid: ${device_name} AP + password: ${fallback_ap_password} + ap_timeout: 10min # Time until it brings up fallback AP. default is 1min + # Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID + fast_connect: "${wifi_fast_connect}" + # Define dns domain / suffix to add to hostname + domain: "${dns_domain}" + +#captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails + +############################################# +# Enable Over the Air Update Capability +# https://esphome.io/components/ota.html?highlight=ota +############################################# +ota: + - platform: esphome + password: ${local_ota_pass} + version: 2 + +############################################# +# Safe Mode +# Safe mode will detect boot loops +# https://esphome.io/components/safe_mode +############################################# +safe_mode: + +############################################# +# Network +# global configuration for all types of networks +# https://esphome.io/components/network.html +############################################# +network: + enable_ipv6: ${ipv6_enable} \ No newline at end of file diff --git a/esphome/common/sensors_common.yaml b/esphome/common/sensors_common.yaml index 4e8e2f4..d924dd2 100644 --- a/esphome/common/sensors_common.yaml +++ b/esphome/common/sensors_common.yaml @@ -1,7 +1,7 @@ -############################################# +########################################################################################## # GENERAL COMMON SENSORS # https://esphome.io/components/sensor/ -############################################# +########################################################################################## sensor: - platform: uptime # Uptime for this device in seconds name: "Uptime (s):" @@ -22,16 +22,23 @@ sensor: entity_category: "diagnostic" device_class: "" + # Only works with esp8266 + #- platform: adc + # pin: VCC + # name: "VCC Voltage" + # id: vcc_voltage_sensor + # entity_category: diagnostic + binary_sensor: - platform: status name: "Network Status" icon: mdi:check-network-outline entity_category: diagnostic -############################################# +########################################################################################## # Text Sensors # https://esphome.io/components/text_sensor/index.html -############################################# +########################################################################################## text_sensor: ###################################################### # General ESPHome Info @@ -58,9 +65,9 @@ text_sensor: update_interval: ${local_update_interval} entity_category: "diagnostic" - ###################################################### + ################################################################################################### # Creates a sensor of the uptime of the device, in formatted days, hours, minutes and seconds - ###################################################### + ################################################################################################### # - platform: template # name: "Uptime (Days)" # entity_category: diagnostic @@ -109,6 +116,10 @@ text_sensor: # } # icon: mdi:clock-start +########################################################################################## +# BUTTONS +# Diagnostic buttons, activated if needed in HA +########################################################################################## button: - platform: safe_mode name: "Safe Mode Restart:" diff --git a/esphome/esp-3dprinterpow.yaml b/esphome/esp-3dprinterpow.yaml new file mode 100644 index 0000000..7fc3a84 --- /dev/null +++ b/esphome/esp-3dprinterpow.yaml @@ -0,0 +1,183 @@ +############################################# +############################################# +# 3D PRINTER POWER AND SWITCH +# V1.0 2025-06-29 Initial Version +############################################# +# Sonoff POW R1 +# https://devices.esphome.io/devices/Sonoff-POW-R1 +# +# NOTES +# - +# +############################################# +############################################# + +############################################# +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +############################################# +substitutions: + device_name: "esp-3dprinterpow" # Reference name for the device in the system. + project_name: "Sonoff Technologies.POW R1" # Project Details + project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + entity_prefix: "Load" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current. + friendly_name: "3D Printer Power" + description_comment: "3D Printer inline monitor and switch override using a Sonoff Pow R1." + device_area: "Laundry" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names + static_ip_address: !secret esp-3dprinterpow_ip + log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +############################################# +# ESPHome +# https://esphome.io/components/esphome.html +############################################# +esphome: + name: "${device_name}" + friendly_name: "${friendly_name}" + comment: "${description_comment}" # Appears on the esphome page in HA + area: "${device_area}" + project: + name: "${project_name}" + version: "${project_version}" + #on_boot: + #priority: 200 + #then: + # - switch.turn_on: "virtual_button" + +############################################# +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +############################################# +esp8266: + board: esp01_1m + early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. + board_flash_mode: dout # Default is dout + +############################################# +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +############################################# +logger: + level: ${log_level} #INFO Level suggested, or DEBUG for testing + #baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +############################################# +# STATUS LED +# https://esphome.io/components/status_led.html +############################################# +#status_led: +# pin: +# number: GPIO2 +# inverted: yes + +############################################# +# SENSORS +# https://esphome.io/components/binary_sensor/ +############################################# +binary_sensor: + - platform: gpio + pin: + number: GPIO00 + mode: INPUT_PULLUP + inverted: True + name: Button + on_press: + - switch.toggle: virtual_button + - platform: template + name: ${entity_prefix} Running + filters: + - delayed_off: 15s + lambda: |- + if (isnan(id(power).state)) { + return {}; + } else if (id(power).state > 4) { + // Running + return true; + } else { + // Not running + return false; + } + +sensor: + - platform: hlw8012 + sel_pin: 5 + cf_pin: 14 + cf1_pin: 13 + update_interval: 2s + current: + name: ${entity_prefix} Current + voltage: + name: ${entity_prefix} Voltage + power: + name: ${entity_prefix} Power + id: power + #on_value_range: + # - above: 4.0 + # then: + # - light.turn_on: led + # - below: 3.0 + # then: + # - light.turn_off: led + +switch: + - platform: template + name: "Relay" + optimistic: true + id: virtual_button + turn_on_action: + - switch.turn_on: relay + - light.turn_on: led + turn_off_action: + - switch.turn_off: relay + - light.turn_off: led + - platform: gpio + id: relay + pin: GPIO12 + #restore_mode: ALWAYS_ON # Or RESTORE_DEFAULT_ON/RESTORE_DEFAULT_OFF + +output: + - platform: esp8266_pwm + id: pow_blue_led + pin: + number: GPIO15 + inverted: True + +light: + - platform: monochromatic + name: Status LED + output: pow_blue_led + id: led \ No newline at end of file diff --git a/esphome/esp-bedrm2ceilingfan.yaml b/esphome/esp-bedrm2ceilingfan.yaml new file mode 100644 index 0000000..9ecb9bf --- /dev/null +++ b/esphome/esp-bedrm2ceilingfan.yaml @@ -0,0 +1,381 @@ +########################################################################################## +########################################################################################## +# CEILING FAN - BEDROOM 2 +# - 3 speed fan using Sonoff IFan02 +# - Also, single Light Output +# +# Controlled by a Sonoff IFan 02 +# +# V1.0 - 2025-07-21 First Setup (and replacement of Tasmota) +# +# NOTES: +# Command the fan with MQTT +# ${mqtt_local_command_full_topic}/speed/set 1,2,3,0,+,- +# ${mqtt_local_command_full_topic}/light/set ON,OFF +# Status of the fan is in MQTT +# ${mqtt_local_command_full_topic}/speed/state 1,2,3,0 +# ${mqtt_local_command_full_topic}/light/state ON,OFF +# +########################################################################################## +########################################################################################## + +########################################################################################## +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +########################################################################################## +substitutions: + # Device Naming + device_name: "esp-bedrm2ceilingfan" + friendly_name: "Bedroom 2 Ceiling Fan" + description_comment: "3 Speed Overhead Ceiling Fan Bedroom 2 :: Sonoff ifan02" + device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + + # Project Naming + project_name: "Sonoff Technologies.Sonoff ifan02" # Project Details + project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + + # Passwords & Secrets + api_key: !secret esp-api_key + ota_pass: !secret esp-ota_pass + static_ip_address: !secret esp-bedrm2ceilingfan_ip # unfortunately you can't use substitutions inside secrets names + mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic + mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic + + # Device Settings + log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + + # MQTT LOCAL Controls + mqtt_device_name: "bedroom2-ceilingfan" + mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA + mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA + + # MQTT REMOTE Controls + + # Button Naming & Icons + + # Switch/Relay Naming & Icons + #relay_icon: "mdi:lightbulb-group" + light_1_name: "Fan Light" + switch_2_name: "Fan 2 Relay" + switch_3_name: "Fan 3 Relay" + switch_4_name: "Fan 4 Relay" + +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +########################################################################################## +# ESPHome +# https://esphome.io/components/esphome.html +########################################################################################## +esphome: + name: "${device_name}" + friendly_name: "${friendly_name}" + comment: "${description_comment}" # Appears on the esphome page in HA + area: "${device_area}" + on_boot: # This weird toggle thing makes sure the states get restored on reboot + priority : -100 + then: + - delay: 200ms + - fan.toggle: ifan02_fan + - fan.toggle: ifan02_fan + - delay: 200ms + - light.toggle: ifan02_light + - delay: 1ms + - light.toggle: ifan02_light + - delay: 1s + - mqtt.publish: + topic: "${mqtt_local_status_topic}/speed/state" + payload: !lambda 'return to_string(id(speed_value));' +# platformio_options: +# build_flags: +# - "-Os" # optimize for size +# - "-Wl,--gc-sections" # drop unused code/data +# - "-fno-exceptions" # strip C++ exceptaions +# - "-fno-rtti" # strip C++ RTTI + +########################################################################################## +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +########################################################################################## +esp8266: + board: esp01_1m # The original sonoff basic + restore_from_flash: True # restore some values on reboot + +preferences: + flash_write_interval: 5min + +mdns: + disabled: True # Disabling will make the build file smaller (and it is still available via static IP) + +########################################################################################## +# GLOBAL VARIABLES +########################################################################################## +globals: + - id: speed_value + type: int + restore_value: yes + initial_value: '0' + +########################################################################################## +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +########################################################################################## +logger: + level: "${log_level}" # INFO Level suggested, or DEBUG for testing + baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM, Serial control) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +########################################################################################## +# MQTT COMMANDS +# This adds device-specific MQTT command triggers to the common MQTT configuration. +########################################################################################## +mqtt: + on_message: + # Light control + - topic: "${mqtt_local_command_topic}/light/set" + payload: "ON" + then: + - light.turn_on: ifan02_light + - topic: "${mqtt_local_command_topic}/light/set" + payload: "OFF" + then: + - light.turn_off: ifan02_light + + # Fan speed control (0–3) + ramp up/down (+ / -) + - topic: "${mqtt_local_command_topic}/speed/set" + then: + # 1) Compute new speed_value based on payload + - lambda: |- + std::string s = x; + int val = id(speed_value); + if (s == "+") { + val++; + } else if (s == "-") { + val--; + } else if (s.size() && isdigit(s[0])) { + val = atoi(s.c_str()); + } else { + ESP_LOGE("ifan02", "Invalid speed payload: '%s'", x.c_str()); + return; + } + // Clamp between 0 and 3 + if (val < 0) val = 0; + if (val > 3) val = 3; + id(speed_value) = val; + + # 2) Drive the fan based on the new value + - if: + condition: + lambda: 'return id(speed_value) == 0;' + then: + - fan.turn_off: ifan02_fan + else: + - fan.turn_on: + id: ifan02_fan + speed: !lambda 'return id(speed_value);' + +########################################################################################## +# SWITCH COMPONENT +# https://esphome.io/components/switch/ +########################################################################################## +# Sonoff ifan02 has relays, but they don't need to be shown in HA because +# the speed of the fan is the important part (and combinations of the relays give that) +########################################################################################## +switch: + - platform: gpio + name: "${switch_3_name}" + pin: GPIO4 + id: fan3sw + restore_mode: RESTORE_DEFAULT_OFF + internal: true + - platform: gpio + name: "${switch_2_name}" + pin: GPIO5 + id: fan2sw + restore_mode: RESTORE_DEFAULT_OFF + internal: true + - platform: gpio + name: "${switch_4_name}" + pin: GPIO15 + id: fan4sw + restore_mode: RESTORE_DEFAULT_OFF + internal: true + +########################################################################################## +# SELECT COMPONENT +# https://esphome.io/components/select/index.html +########################################################################################## +select: + - platform: template + name: "Bedroom 2 Fan Speed" + id: bedroom2_fan_speed_select + options: + - "Off" + - "Low" + - "Medium" + - "High" + update_interval: 1s + lambda: |- + switch (id(speed_value)) { + case 1: return esphome::optional("Low"); + case 2: return esphome::optional("Medium"); + case 3: return esphome::optional("High"); + default: return esphome::optional("Off"); + } + set_action: + # OFF + - if: + condition: + lambda: 'return x == "Off";' + then: + - lambda: |- + id(speed_value) = 0; + - fan.turn_off: ifan02_fan + # LOW (1) + - if: + condition: + lambda: 'return x == "Low";' + then: + - lambda: |- + id(speed_value) = 1; + - fan.turn_on: + id: ifan02_fan + speed: 1 + # MEDIUM (2) + - if: + condition: + lambda: 'return x == "Medium";' + then: + - lambda: |- + id(speed_value) = 2; + - fan.turn_on: + id: ifan02_fan + speed: 2 + # HIGH (3) + - if: + condition: + lambda: 'return x == "High";' + then: + - lambda: |- + id(speed_value) = 3; + - fan.turn_on: + id: ifan02_fan + speed: 3 + +################################################################################ +# TEMPLATE OUTPUTS: drive the real relays when the states change +################################################################################ +output: + - platform: gpio + pin: GPIO12 + id: lightrelay + - platform: template + type: float + id: fan_decode + write_action: + - lambda: |- + if (state < 0.25) { + id(fan2sw).turn_off(); + id(fan3sw).turn_off(); + id(fan4sw).turn_off(); + } + else if (state < 0.5) { + id(fan2sw).turn_on(); + id(fan3sw).turn_off(); + id(fan4sw).turn_off(); + } + else if (state < 0.75) { + id(fan2sw).turn_on(); + id(fan3sw).turn_on(); + id(fan4sw).turn_off(); + } + else { + id(fan2sw).turn_on(); + id(fan3sw).turn_off(); + id(fan4sw).turn_on(); + } + +########################################################################################## +# LIGHT COMPONENT +# https://esphome.io/components/light/ +########################################################################################## +light: + - platform: binary + name: "${light_1_name}" + output: lightrelay + restore_mode: RESTORE_DEFAULT_OFF + id: ifan02_light + # publish status updates when the light turns on/off: + on_turn_on: + - mqtt.publish: + topic: "${mqtt_local_status_topic}/light/state" + payload: "ON" + on_turn_off: + - mqtt.publish: + topic: "${mqtt_local_status_topic}/light/state" + payload: "OFF" + +########################################################################################## +# FAN COMPONENT +# https://esphome.io/components/fan/index.html +########################################################################################## +fan: + - platform: speed + output: fan_decode + name: "Fan" + id: ifan02_fan + speed_count: 3 + restore_mode: RESTORE_DEFAULT_OFF + # whenever you explicitly set a speed (1–3): + on_speed_set: + - lambda: |- + id(speed_value) = x; + - mqtt.publish: + topic: "${mqtt_local_status_topic}/speed/state" + payload: !lambda 'return to_string(id(speed_value));' + # whenever the fan goes fully off: + on_turn_off: + - lambda: |- + id(speed_value) = 0; + - mqtt.publish: + topic: "${mqtt_local_status_topic}/speed/state" + payload: "0" + # whenever the fan goes off→on (e.g. via HA’s Fan switch): + on_turn_on: + - lambda: |- + // bump 0→1 if we were off + if (id(speed_value) == 0) id(speed_value) = 1; + - fan.turn_on: + id: ifan02_fan + speed: !lambda 'return id(speed_value);' + - mqtt.publish: + topic: "${mqtt_local_status_topic}/speed/state" + payload: !lambda 'return to_string(id(speed_value));' \ No newline at end of file diff --git a/esphome/esp-bedrm2fanswitch.yaml b/esphome/esp-bedrm2fanswitch.yaml new file mode 100644 index 0000000..135dfc5 --- /dev/null +++ b/esphome/esp-bedrm2fanswitch.yaml @@ -0,0 +1,265 @@ +########################################################################################## +########################################################################################## +# BEDROOM 2 FAN SWITCH +# +# Controlled by a Zemismart KS-811 Triple push button +# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ +# +# V1.0 - 2025-07-23 First Setup (and replacement of Tasmota) +# +# NOTES +# - Switch for Ceiling Fan +# - 3 Switches, Up, Down and Off +# - Remote commands to the fan ${mqtt_remote_command_full_topic}/speed/set 1,2,3,0,+,- +# +########################################################################################## +########################################################################################## + +########################################################################################## +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +########################################################################################## +substitutions: + # Device Naming + device_name: "esp-bedrm2fanswitch" + friendly_name: "Bedroom 2 Fan Wall Switch (3)" + description_comment: "Switch for Bedroom 2 Ceiling Fan using Zemismart KS-811 Triple Push Button. Speed Up (1), Speed Down (2), Fan Off (3)" + device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + + # Project Naming + project_name: "Zemismart Technologies.KS-811-3 (Triple)" # Project Details + project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + + entity_prefix: "Main Bathroom" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current. + + # Passwords + api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names + static_ip_address: !secret esp-bedrm2fanswitch_ip + mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic + mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic + + # Device Settings + #relay_icon: "mdi:heating-coil" + log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + + # MQTT LOCAL Controls + #mqtt_device_name: "bedroom2-ceilingfan-switch" + #mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA + #mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA + + # MQTT REMOTE Controls + mqtt_remote_device_name: "bedroom2-ceilingfan" + mqtt_remote_device_command_topic: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/speed/set" + mqtt_remote_device_command1: "+" + mqtt_remote_device_command2: "-" + mqtt_remote_device_command3: "0" + mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/speed/state" # Topic we will use to view status locally without HA + + # Button Naming & Icons + + # Switch/Relay Naming & Icons + #relay_icon: "mdi:heating-coil" + switch_1_name: "Fan Speed Up" # This is virtual only, no power connected to 1st relay + switch_2_name: "Fan Speed Down" # This is virtual only, no power connected to 2nd relay + switch_3_name: "Fan Off" # This is virtual only, no power connected to 3rd relay + +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +########################################################################################## +# ESPHome +# https://esphome.io/components/esphome.html +########################################################################################## +esphome: + name: ${device_name} + friendly_name: ${friendly_name} + comment: ${description_comment} #Appears on the esphome page in HA + area: ${device_area} + project: + name: "${project_name}" + version: "${project_version}" + platformio_options: + build_flags: + - "-Os" # optimize for size + - "-Wl,--gc-sections" # drop unused code/data + - "-fno-exceptions" # strip C++ exceptions + - "-fno-rtti" # strip C++ RTTI +# on_boot: +# priority: 200 +# then: +# - switch.turn_on: Relay_3 + +########################################################################################## +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +########################################################################################## +esp8266: + board: esp01_1m + early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. + board_flash_mode: dout # Default is dout + +########################################################################################## +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +########################################################################################## +logger: + level: "${log_level}" #INFO Level suggested, or DEBUG for testing + #baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +########################################################################################## +# STATUS LED +# https://esphome.io/components/status_led.html +########################################################################################## +# Status LED for KS-811 is GPIO02 +########################################################################################## +status_led: + pin: + number: GPIO02 + inverted: yes + +########################################################################################## +# BINARY SENSORS +# https://esphome.io/components/binary_sensor/ +########################################################################################## +# Buttons for KS-811-3 are GPIO16, GPIO05, GPIO04 +########################################################################################## +binary_sensor: + - platform: gpio + pin: + number: GPIO16 + mode: INPUT + inverted: True + name: "Button 1: ${switch_1_name}" + on_press: + - mqtt.publish: + topic: "${mqtt_remote_device_command_topic}" + payload: "${mqtt_remote_device_command1}" + + - platform: gpio + pin: + number: GPIO05 + mode: INPUT + inverted: True + name: "Button 2: ${switch_2_name}" + on_press: + - mqtt.publish: + topic: "${mqtt_remote_device_command_topic}" + payload: "${mqtt_remote_device_command2}" + + - platform: gpio + pin: + number: GPIO4 + mode: INPUT + inverted: True + name: "Button 3: ${switch_3_name}" + on_press: + - mqtt.publish: + topic: "${mqtt_remote_device_command_topic}" + payload: "${mqtt_remote_device_command3}" + +########################################################################################## +# SWITCH COMPONENT +# https://esphome.io/components/switch/ +########################################################################################## +# Relays for KS-811-3 are GPIO13, GPIO12, GPIO14 +########################################################################################## +switch: + - platform: gpio + name: "Relay 1: ${switch_1_name}" + pin: GPIO13 + id: Relay_1 + - platform: gpio + name: "Relay 2: ${switch_2_name}" + pin: GPIO12 + id: Relay_2 + - platform: gpio + name: "Relay 3: ${switch_3_name}" + pin: GPIO14 + id: Relay_3 + +mqtt: + on_message: + - topic: "${mqtt_local_status_topic}" + then: + - lambda: |- + int val = atoi(x.c_str()); + ESP_LOGI("fan_switch", "Received requested speed: %d", val); + + // Desired states + bool r1 = false; + bool r2 = false; + bool r3 = false; + + switch (val) { + case 1: + r3 = true; + break; + case 2: + r2 = true; + r3 = true; + break; + case 3: + r1 = true; + r2 = true; + r3 = true; + break; + case 0: + default: + // all remain false + break; + } + + // Only change relays if necessary + if (id(Relay_1).state != r1) { + if (r1) { + id(Relay_1).turn_on(); + } else { + id(Relay_1).turn_off(); + } + } + + if (id(Relay_2).state != r2) { + if (r2) { + id(Relay_2).turn_on(); + } else { + id(Relay_2).turn_off(); + } + } + + if (id(Relay_3).state != r3) { + if (r3) { + id(Relay_3).turn_on(); + } else { + id(Relay_3).turn_off(); + } + } \ No newline at end of file diff --git a/esphome/esp-bedrm2lights.yaml b/esphome/esp-bedrm2lights.yaml new file mode 100644 index 0000000..f41347e --- /dev/null +++ b/esphome/esp-bedrm2lights.yaml @@ -0,0 +1,180 @@ +########################################################################################## +########################################################################################## +# LAUNDRY MAIN LIGHTSWITCH +# V3.5 2025-07-24 YAML tidyups +########################################################################################## +# Zemismart KS-811 Double push button +# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ +# +# NOTES +# - +# +########################################################################################## +########################################################################################## + +########################################################################################## +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +########################################################################################## +substitutions: + # Device Naming + device_name: "esp-bedrm2lights" + friendly_name: "Bedroom 2 Lightswitch (2)" + description_comment: "Bedroom 2 Main Lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1), Desk Lights (2)" + device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + + # Project Naming + project_name: "Zemismart Technologies.KS-811 Double" # Project Details + project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + + # Passwords & Secrets + api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names + static_ip_address: !secret esp-bedrm2lights_ip + #mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic + #mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic + + # Device Settings + #relay_icon: "mdi:lightbulb-group" + log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + + # MQTT LOCAL Controls + #mqtt_device_name: "bedroom2-lights" + #mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA + #mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA + + # Switch Naming + switch_1_name: "Main Lights" + switch_2_name: "Desk Lights" + #switch_3_name: "Nil" + +######################################################################################### +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +######################################################################################### +# ESPHome +# https://esphome.io/components/esphome.html +######################################################################################### +esphome: + name: "${device_name}" + friendly_name: "${friendly_name}" + comment: "${description_comment}" # Appears on the esphome page in HA + area: "${device_area}" + project: + name: "${project_name}" + version: "${project_version}" + #on_boot: + # priority: 200 + # then: + # - switch.turn_on: Relay_2 + +######################################################################################### +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +######################################################################################### +esp8266: + board: esp01_1m + early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. + board_flash_mode: dout # Default is dout + +######################################################################################### +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +############################################# +logger: + level: "${log_level}" #INFO Level suggested, or DEBUG for testing + #baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +######################################################################################### +# STATUS LED +# https://esphome.io/components/status_led.html +######################################################################################### +status_led: + pin: + number: GPIO2 + inverted: yes + +######################################################################################### +# BINARY SENSORS +# https://esphome.io/components/binary_sensor/ +######################################################################################### +binary_sensor: + - platform: gpio + pin: + number: GPIO16 + mode: INPUT + inverted: True + name: "Button 1: ${switch_1_name}" + on_press: + - switch.toggle: Relay_1 + + - platform: gpio + pin: + number: GPIO05 + mode: INPUT + inverted: True + name: "Button 2: ${switch_2_name}" + on_press: + - switch.toggle: Relay_2 + +# KS-811-2 is a double only +# - platform: gpio +# pin: +# number: GPIO4 +# mode: INPUT +# inverted: True +# name: "Button 3: ${switch_3_name}" +# on_press: +# - switch.toggle: Relay_3 + +######################################################################################### +# SWITCH COMPONENT +# https://esphome.io/components/switch/ +######################################################################################### +switch: + - platform: gpio + name: "Relay 1: ${switch_1_name}" + pin: GPIO13 + id: Relay_1 + + - platform: gpio + name: "Relay 2: ${switch_2_name}" + pin: GPIO12 + id: Relay_2 + +# KS-811-2 is a double only +# - platform: gpio +# name: "Relay 3: ${switch_3_name}" +# pin: GPIO14 +# id: Relay_3 + + diff --git a/esphome/esp-downstbathswitch.yaml b/esphome/esp-downstbathswitch.yaml index 06dbbff..8a29552 100644 --- a/esphome/esp-downstbathswitch.yaml +++ b/esphome/esp-downstbathswitch.yaml @@ -22,7 +22,7 @@ substitutions: device_name: "esp-downstbathswitch" friendly_name: "Downstairs Bath Lightswitch (3)" description_comment: "Downstairs Bathroom Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Light (1), Cabinet Light (2), Extract Fan (3)" - device_area: "Downstairs Bathroom" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. # Project Naming project_name: "Zemismart Technologies.KS-811 Triple" # Project Details @@ -42,24 +42,27 @@ substitutions: switch_2_name: "Cabinet Light" switch_3_name: "Extract Fan" # This is virtual only, no power connected to 3rd relay -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" -# common_webportal: !include -# file: common/webportal_common.yaml -# common_mqtt: !include -# file: common/mqtt_common.yaml + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include diff --git a/esphome/esp-downstbathtowelrail.yaml b/esphome/esp-downstbathtowelrail.yaml index bfb7c97..56a4532 100644 --- a/esphome/esp-downstbathtowelrail.yaml +++ b/esphome/esp-downstbathtowelrail.yaml @@ -54,7 +54,7 @@ substitutions: device_name: "esp-downstbathtowelrail" friendly_name: "Downstairs Bathroom Towelrail" description_comment: "Heated Towel Rail, Downstairs Bathroom :: Sonoff Basic" - device_area: "Downstairs Bathroom" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. # Project Naming project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details @@ -78,24 +78,27 @@ substitutions: evening_on_default: "1260" # Default in minutes from midnight. Default 21:00 => 1260 evening_off_default: "1320" # Default in minutes from midnight. Default 22:00 => 1320 => 1440 is midnight -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" -# common_webportal: !include -# file: common/webportal_common.yaml + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -122,6 +125,8 @@ esphome: on_boot: priority: 900 # High priority to run after globals are initialized then: + # This evaluates if we switch on 4+ times in 20 seconds + # If so, just change to on mode permanently. - lambda: |- // 1) Figure out the current time in "seconds from midnight" // using SNTP if available, otherwise current_mins * 60. @@ -159,6 +164,7 @@ esphome: id(boost_timer) = 0; // and reset boost_timer = 0 (for time sync if no sntp) ESP_LOGI("power_cycle", "Boot count=%d => BOOST mode", id(boot_count)); } + - script.execute: evaluate_relay_state # Check what the relay should be doing straight away ############################################# # ESP Platform and Framework @@ -218,31 +224,31 @@ globals: # Morning On time (minutes from midnight), - id: morning_on type: int - restore_value: False + restore_value: true initial_value: "${morning_on_default}" # Morning Off time (minutes from midnight), - id: morning_off type: int - restore_value: False + restore_value: true initial_value: "${morning_off_default}" # Evening On time (minutes from midnight), - id: evening_on type: int - restore_value: False + restore_value: true initial_value: "${evening_on_default}" # Evening Off time (minutes from midnight), - id: evening_off type: int - restore_value: False + restore_value: true initial_value: "${evening_off_default}" # Boost Duration (minutes), - id: boost_duration type: int - restore_value: False + restore_value: true initial_value: "${boost_duration_default}" #################################################### @@ -254,7 +260,7 @@ globals: #################################################### - id: operation_mode type: int - restore_value: false + restore_value: true initial_value: "2" #################################################### @@ -446,7 +452,6 @@ text_sensor: lambda: |- int hour = id(morning_off) / 60; int minute = id(morning_off) % 60; - // Increase buffer size to 8 just to be safe // Increase to 16 for safety char buff[16]; snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute); @@ -461,7 +466,6 @@ text_sensor: lambda: |- int hour = id(evening_on) / 60; int minute = id(evening_on) % 60; - // Increase buffer size to 8 just to be safe // Increase to 16 for safety char buff[16]; snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute); @@ -476,7 +480,6 @@ text_sensor: lambda: |- int hour = id(evening_off) / 60; int minute = id(evening_off) % 60; - // Increase buffer size to 8 just to be safe // Increase to 16 for safety char buff[16]; snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute); @@ -584,6 +587,23 @@ button: id(operation_mode) = 3; # 2) immediately re-evaluate relay state - script.execute: evaluate_relay_state + - platform: template + name: "Default timer settings" + id: default_timer_settings_button + icon: "mdi:restore" + on_press: + - lambda: |- + // Restore all timing globals to their YAML defaults + id(morning_on) = ${morning_on_default}; + id(morning_off) = ${morning_off_default}; + id(evening_on) = ${evening_on_default}; + id(evening_off) = ${evening_off_default}; + id(boost_duration)= ${boost_duration_default}; + // Reset mode to TIMER and clear any running boost + id(operation_mode)= 2; + id(boost_timer) = 0; + ESP_LOGI("timer","Default timer settings applied"); + - script.execute: evaluate_relay_state ################################################################################################# # SELECT COMPONENT diff --git a/esphome/esp-downstbedrm1lights.yaml b/esphome/esp-downstbedrm1lights.yaml new file mode 100644 index 0000000..432c8fa --- /dev/null +++ b/esphome/esp-downstbedrm1lights.yaml @@ -0,0 +1,186 @@ +########################################################################################## +########################################################################################## +# DOWNSTAIRS BEDROOM 1 LIGHTS +# V3.5 2025-07-24 YAML tidyups +########################################################################################## +# Zemismart KS-811 Triple push button +# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ +# +# NOTES +# - +# +########################################################################################## +########################################################################################## + +########################################################################################## +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +########################################################################################## +substitutions: + # Device Naming + device_name: "esp-downstbedrm1lights" + friendly_name: "Downstairs Bedroom 1 Lightswitch (3)" + description_comment: "Downstairs Bedroom 1 Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Lights (1), Wardrobe Lights (2), Spare (3)" + device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + + # Project Naming + project_name: "Zemismart Technologies.KS-811 Triple" # Project Details + project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + + # Passwords & Secrets + api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names + static_ip_address: !secret esp-downstbedrm1lights_ip + #mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic + #mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic + + # Device Settings + log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + + # MQTT LOCAL Controls + #mqtt_device_name: "downst-bedroom2-lights" + #mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA + #mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA + + # MQTT REMOTE Controls + + # Switch/Relay/Button Naming & Icons + #relay_icon: "mdi:lightbulb-group" + switch_1_name: "Main Lights" + switch_2_name: "Wardrobe Lights" + switch_3_name: "Spare" + +######################################################################################### +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +######################################################################################### +# ESPHome +# https://esphome.io/components/esphome.html +######################################################################################### +esphome: + name: "${device_name}" + friendly_name: "${friendly_name}" + comment: "${description_comment}" # Appears on the esphome page in HA + area: "${device_area}" + project: + name: "${project_name}" + version: "${project_version}" + #on_boot: + # priority: 200 + # then: + # - switch.turn_on: Relay_2 + +######################################################################################### +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +######################################################################################### +esp8266: + board: esp01_1m + early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. + board_flash_mode: dout # Default is dout + +######################################################################################### +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +############################################# +logger: + level: "${log_level}" #INFO Level suggested, or DEBUG for testing + #baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +######################################################################################### +# STATUS LED +# https://esphome.io/components/status_led.html +######################################################################################### +status_led: + pin: + number: GPIO2 + inverted: yes + +######################################################################################### +# BINARY SENSORS +# https://esphome.io/components/binary_sensor/ +######################################################################################### +binary_sensor: +# GPIO16 for KS-811 first button + - platform: gpio + pin: + number: GPIO16 + mode: INPUT + inverted: True + name: "Button 1: ${switch_1_name}" + on_press: + - switch.toggle: Relay_1 + +# GPIO05 for second button (only for KS-811-2 Double or -3 Triple) + - platform: gpio + pin: + number: GPIO05 + mode: INPUT + inverted: True + name: "Button 2: ${switch_2_name}" + on_press: + - switch.toggle: Relay_2 + +# GPIO04 for third button (only for KS-811-3 Triple) + - platform: gpio + pin: + number: GPIO4 + mode: INPUT + inverted: True + name: "Button 3: ${switch_3_name}" + on_press: + - switch.toggle: Relay_3 + +######################################################################################### +# SWITCH COMPONENT +# https://esphome.io/components/switch/ +######################################################################################### +switch: +# GPIO13 for KS-811 first relay + - platform: gpio + name: "Relay 1: ${switch_1_name}" + pin: GPIO13 + id: Relay_1 + +# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple) + - platform: gpio + name: "Relay 2: ${switch_2_name}" + pin: GPIO12 + id: Relay_2 + +# GPIO14 for third relay (only for KS-811-3 Triple) + - platform: gpio + name: "Relay 3: ${switch_3_name}" + pin: GPIO14 + id: Relay_3 + + diff --git a/esphome/esp-downstbedrm2lights.yaml b/esphome/esp-downstbedrm2lights.yaml new file mode 100644 index 0000000..92f491a --- /dev/null +++ b/esphome/esp-downstbedrm2lights.yaml @@ -0,0 +1,187 @@ +########################################################################################## +########################################################################################## +# DOwNSTAIRS BEDROOM 2 LIGHTSWITCH +# V3.5 2025-07-24 YAML tidyups +########################################################################################## +# Zemismart KS-811 Single push button +# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ +# +# NOTES +# - +# +########################################################################################## +########################################################################################## + +########################################################################################## +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +########################################################################################## +substitutions: + # Device Naming + device_name: "esp-downstbedrm2lights" + friendly_name: "Downstairs Bedroom 2 Lightswitch (1)" + description_comment: "Downstairs Bedroom 2 Main Lightswitch using a Zemismart KS-811 Single Push Button. Main Lights (1)" + device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + + # Project Naming + project_name: "Zemismart Technologies.KS-811 Single" # Project Details + project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + + # Passwords & Secrets + api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names + static_ip_address: !secret esp-downstbedrm2lights_ip + #mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic + #mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic + + # Device Settings + log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + + # MQTT LOCAL Controls + #mqtt_device_name: "downst-bedroom2-lights" + #mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA + #mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA + + # MQTT REMOTE Controls + + # Switch/Relay/Button Naming & Icons + #relay_icon: "mdi:lightbulb-group" + switch_1_name: "Main Lights" + #switch_2_name: "Nil" + #switch_3_name: "Nil" + +######################################################################################### +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +######################################################################################### +# ESPHome +# https://esphome.io/components/esphome.html +######################################################################################### +esphome: + name: "${device_name}" + friendly_name: "${friendly_name}" + comment: "${description_comment}" # Appears on the esphome page in HA + area: "${device_area}" + project: + name: "${project_name}" + version: "${project_version}" + #on_boot: + # priority: 200 + # then: + # - switch.turn_on: Relay_2 + +######################################################################################### +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +######################################################################################### +esp8266: + board: esp01_1m + early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. + board_flash_mode: dout # Default is dout + +######################################################################################### +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +############################################# +logger: + level: "${log_level}" #INFO Level suggested, or DEBUG for testing + #baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +######################################################################################### +# STATUS LED +# https://esphome.io/components/status_led.html +######################################################################################### +status_led: + pin: + number: GPIO2 + inverted: yes + +######################################################################################### +# BINARY SENSORS +# https://esphome.io/components/binary_sensor/ +######################################################################################### +binary_sensor: +# GPIO16 for KS-811 first button UNLESS +# it is a single button KS-811 in which case it is GPIO00 + - platform: gpio + pin: + number: GPIO00 + mode: INPUT + inverted: True + name: "Button 1: ${switch_1_name}" + on_press: + - switch.toggle: Relay_1 + +# GPIO05 for second button (only for KS-811-2 Double or -3 Triple) +# - platform: gpio +# pin: +# number: GPIO05 +# mode: INPUT +# inverted: True +# name: "Button 2: ${switch_2_name}" +# on_press: +# - switch.toggle: Relay_2 + +# GPIO04 for third button (only for KS-811-3 Triple) +# - platform: gpio +# pin: +# number: GPIO4 +# mode: INPUT +# inverted: True +# name: "Button 3: ${switch_3_name}" +# on_press: +# - switch.toggle: Relay_3 + +######################################################################################### +# SWITCH COMPONENT +# https://esphome.io/components/switch/ +######################################################################################### +switch: +# GPIO13 for KS-811 first button + - platform: gpio + name: "Relay 1: ${switch_1_name}" + pin: GPIO13 + id: Relay_1 + +# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple) +# - platform: gpio +# name: "Relay 2: ${switch_2_name}" +# pin: GPIO12 +# id: Relay_2 + +# GPIO14 for third relay (only for KS-811-3 Triple) +# - platform: gpio +# name: "Relay 3: ${switch_3_name}" +# pin: GPIO14 +# id: Relay_3 + + diff --git a/esphome/esp-downstdishwpower.yaml b/esphome/esp-downstdishwpower.yaml index 818662f..8f0e8c6 100644 --- a/esphome/esp-downstdishwpower.yaml +++ b/esphome/esp-downstdishwpower.yaml @@ -20,7 +20,7 @@ substitutions: device_name: "esp-downstdishwpower" friendly_name: "Downstairs Dishwasher Power" description_comment: "Downstairs Dishwasher Power :: Athom Smart Plug Power V1" - device_area: "Downstairs Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. # Project Naming project_name: "Athom Technology.Smart Plug V1" # Project Details @@ -40,19 +40,26 @@ substitutions: current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16. ########################################################################################## -# PACKAGES -# https://esphome.io/components/esphome.html +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html ########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -61,12 +68,6 @@ packages: local_friendly_name: "${friendly_name}" local_update_interval: "${update_interval}" - # Web and MQTT Packages - #common_webportal: !include - # file: common/webportal_common.yaml - common_mqtt: !include - file: common/mqtt_common.yaml - # Device Specific included packages common_athompowermonV1: !include file: common/athompowermonv1_common.yaml diff --git a/esphome/esp-downstkitchlights.yaml b/esphome/esp-downstkitchlights.yaml index e101b79..e6e7dc6 100644 --- a/esphome/esp-downstkitchlights.yaml +++ b/esphome/esp-downstkitchlights.yaml @@ -22,7 +22,7 @@ substitutions: device_name: "esp-downstkitchlights" friendly_name: "Downstairs Kitchen Lightswitch (3)" description_comment: "Downstairs Kitch Main Lightswitch using a Zemismart KS-811 Triple Push Button. Dining Light (1), Kitchen Light (2), Extract Fan (3)" - device_area: "Downstairs Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. # Passwords api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names @@ -38,24 +38,27 @@ substitutions: switch_2_name: "Kitchen Light" switch_3_name: "Extract Fan" # This is virtual only, no power connected to 3rd relay -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" -# common_webportal: !include -# file: common/webportal_common.yaml -# common_mqtt: !include -# file: common/mqtt_common.yaml + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include diff --git a/esphome/esp-entbtproxy.yaml b/esphome/esp-entbtproxy.yaml index 6a3b08a..0fb592a 100644 --- a/esphome/esp-entbtproxy.yaml +++ b/esphome/esp-entbtproxy.yaml @@ -10,7 +10,7 @@ # If NOT using a secrets file, just replace these with the passwords etc (in quotes) ############################################# substitutions: - devicename: "esp-entbtproxy" + device_name: "esp-entbtproxy" friendly_name: "Outside Entrance Bluetooth Proxy" description_comment: "D1 Mini ESP32 outside entranceway with BT Proxy" api_key: !secret esp-entbtproxy_api_key #unfortunately you can't use substitutions in secrets names @@ -26,38 +26,41 @@ substitutions: # # -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome # https://esphome.io/components/esphome.html ############################################# esphome: - name: ${devicename} + name: ${device_name} friendly_name: ${friendly_name} comment: ${description_comment} #appears on the esphome page in HA min_version: 2024.6.0 # diff --git a/esphome/esp-entmulti.yaml b/esphome/esp-entmulti.yaml index c93fd29..5228ea1 100644 --- a/esphome/esp-entmulti.yaml +++ b/esphome/esp-entmulti.yaml @@ -10,7 +10,7 @@ # If NOT using a secrets file, just replace these with the passwords etc (in quotes) ############################################# substitutions: - devicename: "esp-entmulti" + device_name: "esp-entmulti" friendly_name: "Outside Entrance Multisensor" description_comment: "D1 Mini ESP32 outside entranceway with, mmWave presence, PIR and more" api_key: !secret esp-entmulti_api_key #unfortunately you can't use substitutions in secrets names @@ -44,38 +44,41 @@ substitutions: #web_server_username: !secret web_server_username #web_server_password: !secret web_server_password -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} - common_webportal: !include - file: common/webportal_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml -# common_sntp: !include -# file: common/sntp_common.yaml -# common_general_sensors: !include -# file: common/sensors_common.yaml -# vars: -# local_friendly_name: ${friendly_name} -# local_update_interval: ${update_interval} + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome # https://esphome.io/components/esphome.html ############################################# esphome: - name: ${devicename} + name: ${device_name} friendly_name: ${friendly_name} comment: ${description_comment} #appears on the esphome page in HA min_version: 2024.6.0 @@ -113,80 +116,6 @@ logger: #esp8266_store_log_strings_in_flash: false #tx_buffer_size: 64 -############################################# -# Enable the Home Assistant API -# https://esphome.io/components/api.html -############################################# -#api: -# encryption: -# key: ${api_key} -# on_client_connected: -# - esp32_ble_tracker.start_scan: -# continuous: true -# on_client_disconnected: -# - esp32_ble_tracker.stop_scan: - -############################################# -# Enable Over the Air Update Capability -# https://esphome.io/components/ota.html?highlight=ota -############################################# -#ota: -# - platform: esphome -# password: ${ota_pass} - -############################################# -# Safe Mode -# Safe mode will detect boot loops -# https://esphome.io/components/safe_mode -############################################# -#safe_mode: - -############################################# -# Wifi Settings -# https://esphome.io/components/wifi.html -# -# Power Save mode (can reduce wifi reliability) -# NONE (least power saving, Default for ESP8266) -# LIGHT (Default for ESP32) -# HIGH (most power saving) -############################################# -#wifi: -# ssid: ${wifi_ssid} -# password: ${wifi_password} - #power_save_mode: LIGHT #https://esphome.io/components/wifi.html#wifi-power-save-mode - #manual_ip: #optional static IP address - #static_ip: ${static_ip_address} - #gateway: ${static_ip_gateway} - #subnet: ${static_ip_subnet} -# ap: #Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode -# ssid: $devicename fallback AP -# password: !secret fallback_ap_password -# ap_timeout: 5min #Time until it brings up fallback AP. default is 1min - -############################################# -# Web Portal for display and monitoring -# Turning this off is probably a good idea to save resources. -# https://esphome.io/components/web_server.html -############################################# -#web_server: -# port: 80 -# auth: -# username: ${web_server_username} #probably a good idea to secure it -# password: ${web_server_password} - -############################################# -# MQTT Monitoring -# https://esphome.io/components/mqtt.html?highlight=mqtt -# MUST also have api enabled if you enable MQTT -############################################# -#mqtt: -# broker: ${mqtt_server} -# topic_prefix: ${mqtt_topic}/${devicename} -# username: ${mqtt_username} -# password: ${mqtt_password} -# discovery: False # enable entity discovery (true is default) -# discover_ip: False # enable device discovery (true is default) - ############################################# # i2c bus # https://esphome.io/components/i2c.html diff --git a/esphome/esp-laundrydrypow.yaml b/esphome/esp-laundrydrypow.yaml index 3604d74..b778b1f 100644 --- a/esphome/esp-laundrydrypow.yaml +++ b/esphome/esp-laundrydrypow.yaml @@ -30,31 +30,34 @@ substitutions: log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for for general sensors etc -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml -# common_mqtt: !include -# file: common/mqtt_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome diff --git a/esphome/esp-laundryenv.yaml b/esphome/esp-laundryenv.yaml index 1d67d7e..75a261f 100644 --- a/esphome/esp-laundryenv.yaml +++ b/esphome/esp-laundryenv.yaml @@ -30,31 +30,34 @@ substitutions: log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for for general sensors etc -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml -# common_mqtt: !include -# file: common/mqtt_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome diff --git a/esphome/esp-laundrylights.yaml b/esphome/esp-laundrylights.yaml index bea18ff..cf391d7 100644 --- a/esphome/esp-laundrylights.yaml +++ b/esphome/esp-laundrylights.yaml @@ -1,27 +1,27 @@ -############################################# -############################################# +########################################################################################## +########################################################################################## # LAUNDRY MAIN LIGHTSWITCH +# V3.5 2025-07-24 YAML tidyups # V3.0 2025-06-05 YAML tidyups # V2.0 2025-06-01 Was initially a 3 button switch, now 2 # V1.0 2025-05-30 Initial Version -############################################# -# Zemismart KS-811 Triple push button +########################################################################################## +# Zemismart KS-811 Double push button # pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # # NOTES # - # -############################################# -############################################# +########################################################################################## +########################################################################################## -############################################# +########################################################################################## # SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # If NOT using a secrets file, just replace these with the passwords etc (in quotes) -############################################# +########################################################################################## substitutions: # Device Naming device_name: "esp-laundrylights" - friendly_name: "Laundry Main Lightswitch (2)" description_comment: "Laundry Main Lightswitch using a Zemismart KS-811 Double Push Button. Laundry Lights (1), Laundry Power Signal (2)" device_area: "Laundry" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. @@ -30,37 +30,50 @@ substitutions: project_name: "Zemismart Technologies.KS-811 Double" # Project Details project_version: "v3.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + # Passwords & Secrets api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names static_ip_address: !secret esp-laundrylights_ip + #mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic + #mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # Device Settings + #relay_icon: "mdi:lightbulb-group" log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for for general sensors etc + # MQTT Controls + #mqtt_device_name: "bedroom2-ceilingfan" + #mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA + #mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA + # Switch Naming switch_1_name: "Laundry Lights" switch_2_name: "Laundry Power Enable" # This is virtual only, no power connected to 3rd relay - #switch_3_name: "Spare" + #switch_3_name: "Fan 3 Relay" + #switch_4_name: "Fan 4 Relay" -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +######################################################################################### +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" -# common_webportal: !include -# file: common/webportal_common.yaml -# common_mqtt: !include -# file: common/mqtt_common.yaml + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -69,10 +82,10 @@ packages: local_friendly_name: "${friendly_name}" local_update_interval: "${update_interval}" -############################################# +######################################################################################### # ESPHome # https://esphome.io/components/esphome.html -############################################# +######################################################################################### esphome: name: "${device_name}" friendly_name: "${friendly_name}" @@ -86,16 +99,16 @@ esphome: then: - switch.turn_on: Relay_2 -############################################# +######################################################################################### # ESP Platform and Framework # https://esphome.io/components/esp32.html -############################################# +######################################################################################### esp8266: board: esp01_1m early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. board_flash_mode: dout # Default is dout -############################################# +######################################################################################### # ESPHome Logging Enable # https://esphome.io/components/logger.html ############################################# @@ -105,19 +118,19 @@ logger: #esp8266_store_log_strings_in_flash: false #tx_buffer_size: 64 -############################################# +######################################################################################### # STATUS LED # https://esphome.io/components/status_led.html -############################################# +######################################################################################### status_led: pin: number: GPIO2 inverted: yes -############################################# +######################################################################################### # BINARY SENSORS # https://esphome.io/components/binary_sensor/ -############################################# +######################################################################################### binary_sensor: - platform: gpio pin: @@ -147,10 +160,10 @@ binary_sensor: # on_press: # - switch.toggle: Relay_3 -############################################# +######################################################################################### # SWITCH COMPONENT # https://esphome.io/components/switch/ -############################################# +######################################################################################### switch: - platform: gpio name: "Relay 1: ${switch_1_name}" diff --git a/esphome/esp-laundryplugpow.yaml b/esphome/esp-laundryplugpow.yaml index 8cc5ccb..e13d821 100644 --- a/esphome/esp-laundryplugpow.yaml +++ b/esphome/esp-laundryplugpow.yaml @@ -30,31 +30,34 @@ substitutions: log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for for general sensors etc -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml -# common_mqtt: !include -# file: common/mqtt_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome diff --git a/esphome/esp-laundrywashpow.yaml b/esphome/esp-laundrywashpow.yaml index 6fc4bce..264db42 100644 --- a/esphome/esp-laundrywashpow.yaml +++ b/esphome/esp-laundrywashpow.yaml @@ -30,31 +30,34 @@ substitutions: log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for for general sensors etc -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include -# file: common/mqtt_common.yaml -# common_sntp: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome diff --git a/esphome/esp-mainbathfancombo.yaml b/esphome/esp-mainbathfancombo.yaml index 794820d..c4f09dd 100644 --- a/esphome/esp-mainbathfancombo.yaml +++ b/esphome/esp-mainbathfancombo.yaml @@ -23,7 +23,7 @@ substitutions: description_comment: "Main Bathroom Fan/Heat Switch using a Zemismart KS-811 Double Push Button. Extract Fan (1), IR heater (2)" device_area: "Laundry" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. - # Project Naming + # Project Naming project_name: "Zemismart Technologies.KS-811-2 (Double)" # Project Details project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version @@ -45,34 +45,34 @@ substitutions: mqtt_remote_device1_command_topic: "${mqtt_main_command_topic}/masterbath-towelrail/operation" mqtt_remote_device1_command1: "BOOST" -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - device_name: ${device_name} - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml vars: - device_name: ${device_name} + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome diff --git a/esphome/esp-mainbathlights.yaml b/esphome/esp-mainbathlights.yaml index 3fe4061..8dbba63 100644 --- a/esphome/esp-mainbathlights.yaml +++ b/esphome/esp-mainbathlights.yaml @@ -30,34 +30,34 @@ substitutions: log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for for general sensors etc -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - device_name: ${device_name} - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml vars: - device_name: ${device_name} + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome diff --git a/esphome/esp-maindishwasherspower.yaml b/esphome/esp-maindishwasherspower.yaml index a312134..5f94ebc 100644 --- a/esphome/esp-maindishwasherspower.yaml +++ b/esphome/esp-maindishwasherspower.yaml @@ -39,19 +39,26 @@ substitutions: current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16. ########################################################################################## -# PACKAGES -# https://esphome.io/components/esphome.html +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html ########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -60,12 +67,6 @@ packages: local_friendly_name: "${friendly_name}" local_update_interval: "${update_interval}" - # Web and MQTT Packages - #common_webportal: !include - # file: common/webportal_common.yaml - #common_mqtt: !include - # file: common/mqtt_common.yaml - # Device Specific included packages common_athompowermonV1: !include file: common/athompowermonv1_common.yaml diff --git a/esphome/esp-masterbathtowelrail.yaml b/esphome/esp-masterbathtowelrail.yaml index f965243..b916abb 100644 --- a/esphome/esp-masterbathtowelrail.yaml +++ b/esphome/esp-masterbathtowelrail.yaml @@ -78,24 +78,27 @@ substitutions: evening_on_default: "1260" # Default in minutes from midnight. Default 21:00 => 1260 evening_off_default: "1439" # Default in minutes from midnight. Default 23:59 => 1439 => 1440 is midnight -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" - common_webportal: !include - file: common/webportal_common.yaml + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -122,6 +125,8 @@ esphome: on_boot: priority: 900 # High priority to run after globals are initialized then: + # This evaluates if we switch on 4+ times in 20 seconds + # If so, just change to on mode permanently. - lambda: |- // 1) Figure out the current time in "seconds from midnight" // using SNTP if available, otherwise current_mins * 60. @@ -159,6 +164,7 @@ esphome: id(boost_timer) = 0; // and reset boost_timer = 0 (for time sync if no sntp) ESP_LOGI("power_cycle", "Boot count=%d => BOOST mode", id(boot_count)); } + - script.execute: evaluate_relay_state # Check what the relay should be doing straight away ############################################# # ESP Platform and Framework @@ -166,7 +172,7 @@ esphome: ############################################# esp8266: board: esp01_1m # The original sonoff basic - restore_from_flash: True # restore some values on reboot + restore_from_flash: true # restore some values on reboot preferences: flash_write_interval: 5min @@ -218,31 +224,31 @@ globals: # Morning On time (minutes from midnight), - id: morning_on type: int - restore_value: False + restore_value: true initial_value: "${morning_on_default}" # Morning Off time (minutes from midnight), - id: morning_off type: int - restore_value: False + restore_value: true initial_value: "${morning_off_default}" # Evening On time (minutes from midnight), - id: evening_on type: int - restore_value: False + restore_value: true initial_value: "${evening_on_default}" # Evening Off time (minutes from midnight), - id: evening_off type: int - restore_value: False + restore_value: true initial_value: "${evening_off_default}" # Boost Duration (minutes), - id: boost_duration type: int - restore_value: False + restore_value: true initial_value: "${boost_duration_default}" #################################################### @@ -254,14 +260,13 @@ globals: #################################################### - id: operation_mode type: int - restore_value: false + restore_value: true initial_value: "2" #################################################### # current_mins is set if SNTP is invalid. # We assume user powers on the device at 12:00 noon # => 12 * 60 = 720 minutes from midnight. - # Not restored, so it resets each boot. #################################################### - id: current_mins type: int @@ -602,6 +607,23 @@ button: id(operation_mode) = 3; # 2) immediately re-evaluate relay state - script.execute: evaluate_relay_state + - platform: template + name: "Default timer settings" + id: default_timer_settings_button + icon: "mdi:restore" + on_press: + - lambda: |- + // Restore all timing globals to their YAML defaults + id(morning_on) = ${morning_on_default}; + id(morning_off) = ${morning_off_default}; + id(evening_on) = ${evening_on_default}; + id(evening_off) = ${evening_off_default}; + id(boost_duration)= ${boost_duration_default}; + // Reset mode to TIMER and clear any running boost + id(operation_mode)= 2; + id(boost_timer) = 0; + ESP_LOGI("timer","Default timer settings applied"); + - script.execute: evaluate_relay_state ################################################################################################# # SELECT COMPONENT diff --git a/esphome/esp-midesklamp1s.yaml b/esphome/esp-midesklamp1s.yaml index f79cd83..74cdb7e 100644 --- a/esphome/esp-midesklamp1s.yaml +++ b/esphome/esp-midesklamp1s.yaml @@ -47,34 +47,34 @@ substitutions: update_interval: "60s" # update time for for general sensors etc room: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: - local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} - -#web_server: !remove - + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome diff --git a/esphome/esp-occupancyoffice.yaml b/esphome/esp-occupancyoffice.yaml index 112d993..3fbee39 100644 --- a/esphome/esp-occupancyoffice.yaml +++ b/esphome/esp-occupancyoffice.yaml @@ -37,31 +37,34 @@ substitutions: # # -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: - local_static_ip_address: ${static_ip_address} - local_ota_pass: ${ota_pass} -# common_api: !include -# file: common/api_common.yaml -# vars: -# local_api_key: ${api_key} -# common_webportal: !include -# file: common/webportal_common.yaml + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include file: common/sensors_common.yaml vars: - local_friendly_name: ${friendly_name} - local_update_interval: ${update_interval} + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" ############################################# # ESPHome @@ -73,29 +76,35 @@ esphome: comment: ${description_comment} #appears on the esphome page in HA min_version: 2024.6.0 area: "${device_area}" - on_boot: #LD1125H Initial Setting, will remember previous values (if set) - priority: -200 - then: - - uart.write: - id: LD1125H_UART_BUS - data: !lambda |- - std::string th1st = "mth1=" + str_sprintf("%.0f",id(LD1125H_mth1).state) +"\r\n"; - return std::vector(th1st.begin(), th1st.end()); - - uart.write: - id: LD1125H_UART_BUS - data: !lambda |- - std::string th2st = "mth2=" + str_sprintf("%.0f",id(LD1125H_mth2).state) +"\r\n"; - return std::vector(th2st.begin(), th2st.end()); - - uart.write: - id: LD1125H_UART_BUS - data: !lambda |- - std::string th3st = "mth3=" + str_sprintf("%.0f",id(LD1125H_mth3).state) +"\r\n"; - return std::vector(th3st.begin(), th3st.end()); - - uart.write: - id: LD1125H_UART_BUS - data: !lambda |- - std::string rmaxst = "rmax=" + str_sprintf("%.1f",id(LD1125H_rmax).state) +"\r\n"; - return std::vector(rmaxst.begin(), rmaxst.end()); + platformio_options: + build_flags: + - "-Os" # optimize for size + - "-Wl,--gc-sections" # drop unused code/data + - "-fno-exceptions" # strip C++ exceptions + #- "-fno-rtti" # strip C++ RTTI + on_boot: + - priority: -200 + then: + - uart.write: + id: LD1125H_UART_BUS + data: !lambda |- + std::string th1st = "mth1=" + str_sprintf("%.0f", id(LD1125H_mth1).state) + "\r\n"; + return std::vector(th1st.begin(), th1st.end()); + - uart.write: + id: LD1125H_UART_BUS + data: !lambda |- + std::string th2st = "mth2=" + str_sprintf("%.0f", id(LD1125H_mth2).state) + "\r\n"; + return std::vector(th2st.begin(), th2st.end()); + - uart.write: + id: LD1125H_UART_BUS + data: !lambda |- + std::string th3st = "mth3=" + str_sprintf("%.0f", id(LD1125H_mth3).state) + "\r\n"; + return std::vector(th3st.begin(), th3st.end()); + - uart.write: + id: LD1125H_UART_BUS + data: !lambda |- + std::string rmaxst = "rmax=" + str_sprintf("%.1f", id(LD1125H_rmax).state) + "\r\n"; + return std::vector(rmaxst.begin(), rmaxst.end()); ############################################# # ESP Platform and Framework diff --git a/esphome/esp-officeduallights.yaml b/esphome/esp-officeduallights.yaml index 2d1027a..1999399 100644 --- a/esphome/esp-officeduallights.yaml +++ b/esphome/esp-officeduallights.yaml @@ -7,12 +7,15 @@ # Controlled by a Sonoff Dual R1 # A sonoff dual uses serial data to turn the relays on/off # +# V2.4 - 2025-06-30 Tidied up MQTT direct relay control (esps can control each other via MQTT) # V2.3 - 2025-06-18 Added MQTT direct relay control # # NOTES: # Command the lights on with MQTT -# ${mqtt_command_topic}/relay2/set ON or OFF -# ${mqtt_command_topic}/relay2/set ON or OFF +# ${mqtt_local_command_full_topic}/relay1/set ON or OFF +# ${mqtt_local_command_full_topic}/relay2/set ON or OFF +# ${mqtt_local_status_full_topic}/relay1/set ON or OFF +# ${mqtt_local_status_full_topic}/relay2/set ON or OFF # ########################################################################################## ########################################################################################## @@ -32,10 +35,12 @@ substitutions: project_name: "Sonoff Technologies.Sonoff Dual R1" # Project Details project_version: "v2.3" # Project V denotes release of yaml file, allowing checking of deployed vs latest version - # Passwords - api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names - ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names - static_ip_address: !secret esp-officeduallights_ip + # Passwords & Secrets + api_key: !secret esp-api_key + ota_pass: !secret esp-ota_pass + static_ip_address: !secret esp-officeduallights_ip # unfortunately you can't use substitutions inside secrets names + mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic + mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # Device Settings relay_icon: "mdi:lightbulb-group" @@ -44,31 +49,38 @@ substitutions: # MQTT Controls mqtt_device_name: "office-dual-lights" - mqtt_main_command_topic: !secret mqtt_main_command_topic - mqtt_topic: "${mqtt_main_command_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external withougt HA - #mqtt_status_topic: "${mqtt_main_status_topic}/esphome/${device_name}" # Topic we will use to read stuff from external withougt HA - #mqtt_main_status_topic: !secret mqtt_main_status_topic - #mqtt_remote_device1_command_topic: "${mqtt_main_command_topic}/masterbath-towelrail/operation" - #mqtt_remote_device1_command1: "BOOST" + mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA + mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA + + # Switch Naming + switch_1_name: "Dual L1 Relay" + relay_1_icon: "mdi:lightbulb" + light_1_name: "Light 1 (Right Hand Bunker Light)" + switch_2_name: "Dual L2 Relay" + relay_2_icon: "mdi:lightbulb" + light_2_name: "Light 2 (Cool White Overhead Lights)" ########################################################################################## # PACKAGES: Included Common Packages -# https://esphome.io/components/esphome.html +# https://esphome.io/components/packages.html ########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" -# common_webportal: !include -# file: common/webportal_common.yaml + #common_webportal: !include + # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -139,24 +151,24 @@ mqtt: # Direct MQTT control for relays via serial commands on_message: # Relay 1 control - - topic: "${mqtt_topic}/relay1/set" + - topic: "${mqtt_local_command_topic}/relay1/set" payload: "ON" then: - switch.turn_on: relay_1 - light.turn_on: light_1 - - topic: "${mqtt_topic}/relay1/set" + - topic: "${mqtt_local_command_topic}/relay1/set" payload: "OFF" then: - switch.turn_off: relay_1 - light.turn_off: light_1 # Relay 2 control - - topic: "${mqtt_topic}/relay2/set" + - topic: "${mqtt_local_command_topic}/relay2/set" payload: "ON" then: - switch.turn_on: relay_2 - light.turn_on: light_2 - - topic: "${mqtt_topic}/relay2/set" + - topic: "${mqtt_local_command_topic}/relay2/set" payload: "OFF" then: - switch.turn_off: relay_2 @@ -206,14 +218,14 @@ binary_sensor: ############################################# switch: - platform: template - name: "Dual L1 Relay" + name: "${switch_1_name}" id: relay_1 optimistic: true - icon: "${relay_icon}" + icon: "${relay_1_icon}" internal: true turn_on_action: - mqtt.publish: - topic: "${mqtt_topic}/relay1/state" + topic: "${mqtt_local_status_topic}/relay1/state" payload: "ON" - if: condition: @@ -224,7 +236,7 @@ switch: - uart.write: [0xA0, 0x04, 0x03, 0xA1] turn_off_action: - mqtt.publish: - topic: "${mqtt_topic}/relay1/state" + topic: "${mqtt_local_status_topic}/relay1/state" payload: "OFF" - if: condition: @@ -234,14 +246,14 @@ switch: else: - uart.write: [0xA0, 0x04, 0x02, 0xA1] - platform: template - name: "Dual L2 Relay" + name: "${switch_2_name}" id: relay_2 optimistic: true - icon: "${relay_icon}" + icon: "${relay_2_icon}" internal: true turn_on_action: - mqtt.publish: - topic: "${mqtt_topic}/relay2/state" + topic: "${mqtt_local_status_topic}/relay2/state" payload: "ON" - if: condition: @@ -252,7 +264,7 @@ switch: - uart.write: [0xA0, 0x04, 0x03, 0xA1] turn_off_action: - mqtt.publish: - topic: "${mqtt_topic}/relay2/state" + topic: "${mqtt_local_status_topic}/relay2/state" payload: "OFF" - if: condition: @@ -288,7 +300,7 @@ output: ########################################################################################## light: - platform: binary - name: "Light 1 (Right Hand Bunker Light)" + name: "${light_1_name}" id: light_1 output: light_output_1 diff --git a/esphome/esp-officeelvcontrol.yaml b/esphome/esp-officeelvcontrol.yaml index f4d2246..910089b 100644 --- a/esphome/esp-officeelvcontrol.yaml +++ b/esphome/esp-officeelvcontrol.yaml @@ -44,12 +44,13 @@ substitutions: ########################################################################################## # PACKAGES: Included Common Packages -# https://esphome.io/components/esphome.html +# https://esphome.io/components/packages.html ########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include @@ -60,6 +61,8 @@ packages: # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include diff --git a/esphome/esp-officelights.yaml b/esphome/esp-officelights.yaml index 2f001e4..62fcace 100644 --- a/esphome/esp-officelights.yaml +++ b/esphome/esp-officelights.yaml @@ -42,24 +42,27 @@ substitutions: switch_2_name: "Daytime Lights" # This is virtual only, no power connected to 2nd relay switch_3_name: "Spare" # This is virtual only, no power connected to 3rd relay -############################################# -# Included Common Packages -# https://esphome.io/components/esphome.html -############################################# +########################################################################################## +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" -# common_webportal: !include -# file: common/webportal_common.yaml -# common_mqtt: !include -# file: common/mqtt_common.yaml + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include diff --git a/esphome/esp-officeusbhubpower.yaml b/esphome/esp-officeusbhubpower.yaml index dd7b1db..82201fe 100644 --- a/esphome/esp-officeusbhubpower.yaml +++ b/esphome/esp-officeusbhubpower.yaml @@ -42,14 +42,15 @@ substitutions: mqtt_device_name: "office-usbhub-power" mqtt_main_topic: "${mqtt_main_command_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external without HA -######################################################################################### +########################################################################################## # PACKAGES: Included Common Packages -# https://esphome.io/components/esphome.html +# https://esphome.io/components/packages.html ########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include @@ -60,6 +61,8 @@ packages: # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include diff --git a/esphome/esp-poollightspower.yaml b/esphome/esp-poollightspower.yaml index c2c7dda..da2b9de 100644 --- a/esphome/esp-poollightspower.yaml +++ b/esphome/esp-poollightspower.yaml @@ -83,19 +83,26 @@ substitutions: evening_off_default: "1350" # Default in minutes from midnight. Default 22:30 => 1350 => 1440 is midnight ########################################################################################## -# Included Common Packages -# https://esphome.io/components/esphome.html +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html ########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -104,12 +111,6 @@ packages: local_friendly_name: "${friendly_name}" local_update_interval: "${update_interval}" - # Web and MQTT Packages - #common_webportal: !include - # file: common/webportal_common.yaml - common_mqtt: !include - file: common/mqtt_common.yaml - # Device Specific included packages common_athompowermonV3: !include file: common/athompowermonv3_common.yaml @@ -134,6 +135,9 @@ esphome: board_build.mcu: esp32c3 board_build.variant: esp32c3 board_build.flash_mode: dio + on_boot: + then: + - script.execute: evaluate_relay_state ########################################################################################## # ESP Platform and Framework @@ -184,31 +188,31 @@ globals: # Morning On time (minutes from midnight), - id: morning_on type: int - restore_value: False + restore_value: true initial_value: "${morning_on_default}" # Morning Off time (minutes from midnight), - id: morning_off type: int - restore_value: False + restore_value: true initial_value: "${morning_off_default}" # Evening On time (minutes from midnight), - id: evening_on type: int - restore_value: False + restore_value: true initial_value: "${evening_on_default}" # Evening Off time (minutes from midnight), - id: evening_off type: int - restore_value: False + restore_value: true initial_value: "${evening_off_default}" # Boost Duration (minutes), - id: boost_duration type: int - restore_value: False + restore_value: true initial_value: "${boost_duration_default}" #################################################### @@ -220,28 +224,26 @@ globals: #################################################### - id: operation_mode type: int - restore_value: false + restore_value: true initial_value: "2" #################################################### # current_mins is set if SNTP is invalid. # We assume user powers on the device at 12:00 noon # => 12 * 60 = 720 minutes from midnight. - # Not restored, so it resets each boot. #################################################### - id: current_mins type: int - restore_value: false + restore_value: true initial_value: "720" # 720 is 12:00 Noon #################################################### # boost_timer: counts minutes in BOOST mode # After 'boost_duration' minutes, revert to TIMER. - # Not restored, so each boot starts fresh at 0. #################################################### - id: boost_timer type: int - restore_value: false + restore_value: true initial_value: "0" ########################################################################################## @@ -576,6 +578,23 @@ button: id(operation_mode) = 3; # 2) immediately re-evaluate relay state - script.execute: evaluate_relay_state + - platform: template + name: "Default timer settings" + id: default_timer_settings_button + icon: "mdi:restore" + on_press: + - lambda: |- + // Restore all timing globals to their YAML defaults + id(morning_on) = ${morning_on_default}; + id(morning_off) = ${morning_off_default}; + id(evening_on) = ${evening_on_default}; + id(evening_off) = ${evening_off_default}; + id(boost_duration)= ${boost_duration_default}; + // Reset mode to TIMER and clear any running boost + id(operation_mode)= 2; + id(boost_timer) = 0; + ESP_LOGI("timer","Default timer settings applied"); + - script.execute: evaluate_relay_state ################################################################################################# # SELECT COMPONENT diff --git a/esphome/esp-poolpumppower.yaml b/esphome/esp-poolpumppower.yaml index 6935040..b5d05b8 100644 --- a/esphome/esp-poolpumppower.yaml +++ b/esphome/esp-poolpumppower.yaml @@ -82,19 +82,26 @@ substitutions: evening_off_default: "1350" # Default in minutes from midnight. Default 22:30 => 1350 => 1440 is midnight ########################################################################################## -# PACKAGES -# https://esphome.io/components/esphome.html +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html ########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include file: common/api_common.yaml vars: local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -103,12 +110,6 @@ packages: local_friendly_name: "${friendly_name}" local_update_interval: "${update_interval}" - # Web and MQTT Packages - #common_webportal: !include - # file: common/webportal_common.yaml - common_mqtt: !include - file: common/mqtt_common.yaml - # Device Specific included packages common_athompowermonV3: !include file: common/athompowermonv3_common.yaml @@ -133,6 +134,9 @@ esphome: board_build.mcu: esp32c3 board_build.variant: esp32c3 board_build.flash_mode: dio + on_boot: + then: + - script.execute: evaluate_relay_state ########################################################################################## # ESP Platform and Framework @@ -183,31 +187,31 @@ globals: # Morning On time (minutes from midnight), - id: morning_on type: int - restore_value: False + restore_value: true initial_value: "${morning_on_default}" # Morning Off time (minutes from midnight), - id: morning_off type: int - restore_value: False + restore_value: true initial_value: "${morning_off_default}" # Evening On time (minutes from midnight), - id: evening_on type: int - restore_value: False + restore_value: true initial_value: "${evening_on_default}" # Evening Off time (minutes from midnight), - id: evening_off type: int - restore_value: False + restore_value: true initial_value: "${evening_off_default}" # Boost Duration (minutes), - id: boost_duration type: int - restore_value: False + restore_value: true initial_value: "${boost_duration_default}" #################################################### @@ -219,14 +223,13 @@ globals: #################################################### - id: operation_mode type: int - restore_value: True + restore_value: true initial_value: "2" #################################################### # current_mins is set if SNTP is invalid. # We assume user powers on the device at 12:00 noon # => 12 * 60 = 720 minutes from midnight. - # Not restored, so it resets each boot. #################################################### - id: current_mins type: int @@ -236,7 +239,6 @@ globals: #################################################### # boost_timer: counts minutes in BOOST mode # After 'boost_duration' minutes, revert to TIMER. - # Not restored, so each boot starts fresh at 0. #################################################### - id: boost_timer type: int @@ -575,6 +577,23 @@ button: id(operation_mode) = 3; # 2) immediately re-evaluate relay state - script.execute: evaluate_relay_state + - platform: template + name: "Default timer settings" + id: default_timer_settings_button + icon: "mdi:restore" + on_press: + - lambda: |- + // Restore all timing globals to their YAML defaults + id(morning_on) = ${morning_on_default}; + id(morning_off) = ${morning_off_default}; + id(evening_on) = ${evening_on_default}; + id(evening_off) = ${evening_off_default}; + id(boost_duration)= ${boost_duration_default}; + // Reset mode to TIMER and clear any running boost + id(operation_mode)= 2; + id(boost_timer) = 0; + ESP_LOGI("timer","Default timer settings applied"); + - script.execute: evaluate_relay_state ################################################################################################# # SELECT COMPONENT diff --git a/esphome/esp-underhouselights.yaml b/esphome/esp-underhouselights.yaml index 4ce041e..c2b658e 100644 --- a/esphome/esp-underhouselights.yaml +++ b/esphome/esp-underhouselights.yaml @@ -28,7 +28,8 @@ substitutions: api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names static_ip_address: !secret esp-underhouselights_ip - mqtt_main_command_topic: !secret mqtt_main_command_topic + mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic + mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # Device Settings log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE @@ -36,7 +37,8 @@ substitutions: # MQTT Controls mqtt_device_name: "underhouse-lights-control" - mqtt_main_topic: "${mqtt_main_command_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external without HA + mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA + mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA # Switch Naming switch_1_name: "Underhouse Entrance Lights" @@ -54,12 +56,13 @@ substitutions: ########################################################################################## # PACKAGES: Included Common Packages -# https://esphome.io/components/esphome.html +# https://esphome.io/components/packages.html ########################################################################################## packages: common_wifi: !include file: common/network_common.yaml vars: + local_device_name: "${device_name}" local_static_ip_address: "${static_ip_address}" local_ota_pass: "${ota_pass}" common_api: !include @@ -70,6 +73,8 @@ packages: # file: common/webportal_common.yaml common_mqtt: !include file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" common_sntp: !include file: common/sntp_common.yaml common_general_sensors: !include @@ -252,12 +257,40 @@ status_led: mqtt: on_message: # Relay 1 control - - topic: "${mqtt_main_topic}/relay1/set" + - topic: "${mqtt_local_command_topic}/relay1/set" payload: "ON" then: - switch.turn_on: relay1 - - topic: "${mqtt_main_topic}/relay1/set" + - topic: "${mqtt_local_command_topic}/relay1/set" payload: "OFF" then: - switch.turn_off: relay1 + # Relay 2 control + - topic: "${mqtt_local_command_topic}/relay2/set" + payload: "ON" + then: + - switch.turn_on: relay2 + - topic: "${mqtt_local_command_topic}/relay2/set" + payload: "OFF" + then: + - switch.turn_off: relay2 + # Relay 3 control + - topic: "${mqtt_local_command_topic}/relay3/set" + payload: "ON" + then: + - switch.turn_on: relay3 + - topic: "${mqtt_local_command_topic}/relay3/set" + payload: "OFF" + then: + - switch.turn_off: relay3 + # Relay 4 control + - topic: "${mqtt_local_command_topic}/relay4/set" + payload: "ON" + then: + - switch.turn_on: relay4 + - topic: "${mqtt_local_command_topic}/relay4/set" + payload: "OFF" + then: + - switch.turn_off: relay4 + diff --git a/packages/moonraker_3dprinter copy.yaml.bak b/packages/moonraker_3dprinter copy.yaml.bak new file mode 100644 index 0000000..6f41f4d --- /dev/null +++ b/packages/moonraker_3dprinter copy.yaml.bak @@ -0,0 +1,370 @@ +rest: + scan_interval: 5 + resource_template: "http://192.168.2.31:7125/server/files/metadata?filename={{ states(('sensor.3d_printer_current_print')) | urlencode }}" + sensor: + - name: printer_3d_file_metadata + unique_id: "192.168.2.315ec44d90-419c-419c-802d-d34071639c08" + json_attributes_path: "$.result" + json_attributes: + - layer_height + - object_height + - thumbnails + value_template: "OK" + +#camera: +# Loading generic IP camera via configuration.yaml is deprecated, it will be automatically imported. Once you have confirmed correct operation, please remove 'generic' (IP camera) section(s) from configuration.yaml +# Directions in the README.md for how to add the Thumbnail now. +# - platform: generic +# name: "3D Printer Thumbnail" +# still_image_url: http://192.168.2.31:7125/server/files/gcodes/{{ states("sensor.3d_printer_object_thumbnails") }} +# verify_ssl: false + +# This no longer works broken in current builds https://www.home-assistant.io/blog/2022/05/04/release-20225/#breaking-changes -> MJPEG IP Camera +# Directions in the README.md for how to add the MJPEG IP Camera now. +# - platform: mjpeg +# name: "3D Printer Camera" +# still_image_url: http://192.168.2.31/webcam/?action=snapshot +# mjpeg_url: http://192.168.2.31/webcam/?action=stream +# verify_ssl: false + +rest_command: + 3d_printer_emergency_stop: + url: "http://192.168.2.31:7125/printer/emergency_stop" + method: post + 3d_printer_firmware_restart: + url: "http://192.168.2.31:7125/printer/firmware_restart" + method: post + 3d_printer_cancel: + url: "http://192.168.2.31:7125/printer/print/cancel" + method: post + 3d_printer_pause: + url: "http://192.168.2.31:7125/printer/print/pause" + method: post + 3d_printer_resume: + url: "http://192.168.2.31:7125/printer/print/resume" + method: post + +sensor: + - platform: rest + name: printer_3d_sensor + unique_id: "192.168.2.313a0c25fa-297d-4c19-b03c-ddf04840682b" + resource: "http://192.168.2.31:7125/printer/objects/query?heater_bed&extruder&print_stats&toolhead&display_status&virtual_sdcard&gcode_move&filament_motion_sensor%20btt_smart_filament&temperature_sensor%20Chamber_Temp" + json_attributes_path: "$.result.status" + json_attributes: + - heater_bed + - extruder + - print_stats + - toolhead + - display_status + - virtual_sdcard + - gcode_move + - "filament_motion_sensor btt_smart_filament_sensor" + - "temperature_sensor Chamber_Temp" + value_template: "OK" + force_update: true + scan_interval: 1 + + - platform: rest + name: printer_3d_info + unique_id: "192.168.2.311cba6677-02bd-4273-9083-b8301bf6943b" + scan_interval: 1 + resource_template: "http://192.168.2.31:7125/printer/info" + json_attributes_path: "$.result" + json_attributes: + - state_message + - state + value_template: "OK" + + - platform: rest + name: printer_3d_server + unique_id: "192.168.2.311cba6677-02bd-4273-9083-b8301bf6949" + scan_interval: 1 + resource_template: "http://192.168.2.31:7125/server/database/item?namespace=mainsail&key=general" + json_attributes_path: "$.result.value" + json_attributes: + - printername + value_template: "OK" + +template: + - binary_sensor: + - name: 3d_printer_filament + unique_id: "192.168.2.315ce32fc9-5e95-49e7-80e7-bfdd2cf1d1fd" + device_class: motion + state: '{{ states.sensor.printer_3d_sensor.attributes["filament_switch_sensor Filament"]["filament_detected"] }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:printer-3d-nozzle-alert + attributes: + friendly_name: "Filament Detected" + - sensor: + - name: 3d_printer_printername + unique_id: "192.168.2.313a0f3144-a801-422f-adb6-e2ed35796074" + state: '{{ states.sensor.printer_3d_server.attributes["printername"]}}' + availability: > + {% set items = ['sensor.printer_3d_server'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:printer-3d + attributes: + friendly_name: "Printer Name" + - name: 3d_printer_chamber_temp + unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f741" + state: '{{ states.sensor.printer_3d_sensor.attributes["temperature_sensor Chamber_Temp"]["temperature"] | float(0) | round(1) }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "°C" + icon: mdi:thermometer + attributes: + friendly_name: "Chamber Actual" + - name: 3d_printer_hotend_target + unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f740" + state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["target"] | float(0) | round(1) }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "°C" + icon: mdi:thermometer + attributes: + friendly_name: "Hotend Target" + - name: 3d_printer_hotend_actual + unique_id: "192.168.2.317c2593fb-a7dd-4ed7-a865-2e4dddddbb40" + state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["temperature"] | float(0) | round(1) }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "°C" + icon: mdi:thermometer + attributes: + friendly_name: "Hotend Actual" + - name: 3d_printer_hotend_power + unique_id: "192.168.2.31c57a1e35-92fa-403e-b3cf-ec1e97ef94cf" + state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["power"] | float(0) | round(3) * 100}}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "%" + icon: mdi:flash + attributes: + friendly_name: "Hotend Power" + - name: 3d_printer_bed_target + unique_id: "192.168.2.31eadec415-c281-4814-8fba-17c6c42670ec" + state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["target"] | float(0) | round(1) }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "°C" + icon: mdi:thermometer + attributes: + friendly_name: "Bed Target" + - name: 3d_printer_bed_actual + unique_id: "192.168.2.31cb33503c-c5d4-4e06-b79b-c1cd64ca2d7a" + state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["temperature"] | float(0) | round(1) }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "°C" + icon: mdi:thermometer + attributes: + friendly_name: "Bed Actual" + - name: 3d_printer_bed_power + unique_id: "192.168.2.31abb2fc5b-8173-4131-a942-fb11e30f4efa" + state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["power"] | float(0) | round(3) * 100 }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "%" + icon: mdi:flash + attributes: + friendly_name: "Bed Power" + - name: 3d_printer_state + unique_id: "192.168.2.31758ce84c-3210-4f29-b6b3-38139180de96" + state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: > + {% set val = states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] %} + {% if val == 'standby' %} + mdi:sleep + {% elif val == 'error' %} + mdi:alert-circle + {% elif val == 'printing' %} + mdi:printer-3d-nozzle + {% elif val == 'paused' %} + mdi:pause-circle + {% elif val == 'complete' %} + mdi:printer-3d + {% else %} + mdi:help-circle + {% endif %} + attributes: + friendly_name: "Printer State" + - name: 3d_printer_current_print + unique_id: "192.168.2.313a0f3144-a801-422f-adb6-e2ed35796072" + state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["filename"]}}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:file + attributes: + friendly_name: "Current Print" + - name: 3d_printer_current_progress + unique_id: "192.168.2.318ec7163b-be00-4a10-8051-48cf9a260a29" + state: '{{ ((states.sensor.printer_3d_sensor.attributes["display_status"]["progress"])*100) | round(0, "floor") }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "%" + icon: mdi:progress-clock + attributes: + friendly_name: "Progress" + - name: 3d_printer_print_time + unique_id: "192.168.2.31e1ac0fac-e8ba-4e05-8fa0-c8d8076f9f63" + state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] |timestamp_custom("%H:%M:%S", 0)}}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:camera-timer + attributes: + friendly_name: "Time Elapsed" + - name: 3d_printer_time_remaining + unique_id: "192.168.2.31e12c8def-5ebe-43a4-9f75-605a0c46fc0f" + state: '{{ (((states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]/states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]- states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]>0 else 0)) | timestamp_custom("%H:%M:%S", 0)}}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:timer-sand + attributes: + friendly_name: "Time Remaining" + - name: 3d_printer_eta + unique_id: "192.168.2.31a2b57068-9a32-4d2c-8cc9-57d2389a9082" + state: '{{ (as_timestamp(now())+((states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]/states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]- states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]>0 else 0)) | timestamp_custom("%H:%M:%S", 1)}}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:av-timer + attributes: + friendly_name: "ETA" + - name: 3d_printer_message + unique_id: "192.168.2.310c418c0d-e59e-4d4e-aa11-8fae53df58f8" + state: '{{ states.sensor.printer_3d_sensor.attributes["display_status"]["message"]}}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:message-cog + attributes: + friendly_name: "Message" + - name: 3d_printer_layer_height + unique_id: "192.168.2.316cca455d-c327-4567-b886-4d7f99714265" + state: '{{ states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float(0) }}' + availability: > + {% set items = ['sensor.printer_3d_file_metadata'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "mm" + icon: mdi:arrow-collapse-down + attributes: + friendly_name: "Layer Height" + - name: 3d_printer_object_height + unique_id: "192.168.2.316d6d9dc0-9a02-4ce4-a797-c84b42e011a6" + state: '{{ (states.sensor.printer_3d_file_metadata.attributes["object_height"] | float(0)) - (states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float(0)) }}' + availability: > + {% set items = ['sensor.printer_3d_file_metadata'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "mm" + icon: mdi:arrow-expand-vertical + attributes: + friendly_name: "Object Height" + - name: 3d_printer_current_height + unique_id: "192.168.2.31d440e568-d4d1-4b3f-85c4-fdacd68c0e1a" + state: '{{ states.sensor.printer_3d_sensor.attributes["gcode_move"]["gcode_position"][2] | float(0) | round(2) }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "mm" + icon: mdi:arrow-collapse-down + attributes: + friendly_name: "Current Height" + - name: 3d_printer_current_layer + unique_id: "192.168.2.316a77acc1-8134-4354-b2f6-390adab81993" + state: '{{ (states("sensor.3d_printer_current_height")|float(0) / states("sensor.3d_printer_layer_height")|float(0))|round(0) }}' + availability: > + {% set items = ['sensor.3d_printer_current_height','sensor.3d_printer_layer_height'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:counter + attributes: + friendly_name: "Current Layer" + - name: 3d_printer_total_layers + unique_id: "192.168.2.3153cfe906-28ec-44cd-926a-b08ffb8766e5" + state: '{{ (states("sensor.3d_printer_object_height")|float(0) / states("sensor.3d_printer_layer_height")|float(0))|round(0) }}' + availability: > + {% set items = ['sensor.3d_printer_object_height','sensor.3d_printer_layer_height'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:counter + attributes: + friendly_name: "Total Layer" + - name: 3d_printer_actual_layer + unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f742" + state: '{{ states.sensor.printer_3d_sensor.attributes.print_stats["info"]["current_layer"] }} / {{ states.sensor.printer_3d_sensor.attributes.print_stats["info"]["total_layer"] }}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:layers-triple + attributes: + friendly_name: "Actual Layer" + - name: 3d_printer_object_thumbnails + unique_id: "192.168.2.3159b37837-b751-4d31-98c2-516a52edf833" + state: > + {% set dir = states('sensor.3d_printer_current_print') %} + {% set thumb = state_attr('sensor.printer_3d_file_metadata','thumbnails') %} + {% set img = (thumb | last).relative_path if thumb else 'not available' %} + {{ (dir.split('/')[:-1] + [img]) | join('/') }} + availability: > + {% set items = ['sensor.printer_3d_file_metadata'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:image + attributes: + friendly_name: "Object Thumbnails" + - name: 3d_printer_state_message + unique_id: "192.168.2.319a5184c9-ac5b-44a9-a691-2b67c243d197" + state: '{{ states.sensor.printer_3d_info.attributes["state_message"] }}' + availability: > + {% set items = ['sensor.printer_3d_info'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:message-cog + attributes: + friendly_name: "State Message" + - name: 3d_printer_heaters_power + unique_id: "192.168.2.313988e9be-c910-4634-8205-38d53170d5a5" + state: '{{ states("sensor.3d_printer_bed_power")|float(0) | round(1) }}% / {{ states("sensor.3d_printer_hotend_power")|float(0) | round(1) }}%' + availability: > + {% set items = ['sensor.3d_printer_bed_power','sensor.3d_printer_hotend_power'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + icon: mdi:meter-electric-outline + attributes: + friendly_name: "Bed and Nozzle Power" diff --git a/packages/moonraker_3dprinter.yaml b/packages/moonraker_3dprinter.yaml new file mode 100644 index 0000000..d8a7dde --- /dev/null +++ b/packages/moonraker_3dprinter.yaml @@ -0,0 +1,197 @@ +# === Add friendly names, icons, and area for printer controls === +homeassistant: + customize: + rest_command.3d_printer_emergency_stop: + friendly_name: "Emergency Stop (K1C)" + area_id: Laundry + icon: mdi:alert-octagon + + rest_command.3d_printer_firmware_restart: + friendly_name: "Firmware Restart (K1C)" + area_id: Laundry + icon: mdi:restart + + rest_command.3d_printer_cancel: + friendly_name: "Cancel Print (K1C)" + area_id: Laundry + icon: mdi:cancel + + rest_command.3d_printer_pause: + friendly_name: "Pause Print (K1C)" + area_id: Laundry + icon: mdi:pause-circle + + rest_command.3d_printer_resume: + friendly_name: "Resume Print (K1C)" + area_id: Laundry + icon: mdi:play-circle + + sensor.printer_3d_file_metadata: + area_id: Laundry + friendly_name: "3D Printer (K1C) Print file data" + + sensor.printer_3d_sensor: + area_id: Laundry + friendly_name: "3D Printer (K1C) Sensors" + + sensor.printer_3d_info: + area_id: Laundry + friendly_name: "3D Printer (K1C) State" + + sensor.printer_3d_server: + area_id: Laundry + friendly_name: "3D Printer (K1C) Print Server" + + sensor.3d_printer_chamber_temp: + area_id: Laundry + + sensor.3d_printer_hotend_target: + area_id: Laundry + + sensor.3d_printer_hotend_actual: + area_id: Laundry + + sensor.3d_printer_hotend_power: + area_id: Laundry + + sensor.3d_printer_bed_target: + area_id: Laundry + + sensor.3d_printer_bed_actual: + area_id: Laundry + + sensor.3d_printer_bed_power: + area_id: Laundry + + sensor.3d_printer_state: + area_id: Laundry + + sensor.3d_printer_current_print: + area_id: Laundry + + sensor.3d_printer_current_progress: + area_id: Laundry + + sensor.3d_printer_print_time: + area_id: Laundry + + sensor.3d_printer_time_remaining: + area_id: Laundry + + sensor.3d_printer_eta: + area_id: Laundry + + sensor.3d_printer_message: + area_id: Laundry + + sensor.3d_printer_layer_height: + area_id: Laundry + + sensor.3d_printer_object_height: + area_id: Laundry + + sensor.3d_printer_current_height: + area_id: Laundry + + sensor.3d_printer_current_layer: + area_id: Laundry + + sensor.3d_printer_total_layers: + area_id: Laundry + + sensor.3d_printer_actual_layer: + area_id: Laundry + + sensor.3d_printer_object_thumbnails: + area_id: Laundry + + sensor.3d_printer_state_message: + area_id: Laundry + + sensor.3d_printer_heaters_power: + area_id: Laundry + + sensor.3d_printer_printername: + area_id: Laundry + + binary_sensor.3d_printer_filament: + area_id: Laundry + + # === REST sensor: File metadata for current 3D print === +rest: + scan_interval: 5 + resource_template: "http://192.168.2.31:7125/server/files/metadata?filename={{ states('sensor.3d_printer_current_print') | urlencode }}" + sensor: + - name: printer_3d_file_metadata + unique_id: "192.168.2.315ec44d90-419c-419c-802d-d34071639c08" + icon: mdi:file-document-outline + json_attributes_path: "$.result" + json_attributes: + - layer_height + - object_height + - thumbnails + value_template: "OK" + +rest_command: + 3d_printer_emergency_stop: + url: "http://192.168.2.31:7125/printer/emergency_stop" + method: post + 3d_printer_firmware_restart: + url: "http://192.168.2.31:7125/printer/firmware_restart" + method: post + 3d_printer_cancel: + url: "http://192.168.2.31:7125/printer/print/cancel" + method: post + 3d_printer_pause: + url: "http://192.168.2.31:7125/printer/print/pause" + method: post + 3d_printer_resume: + url: "http://192.168.2.31:7125/printer/print/resume" + method: post + +sensor: + # === REST sensor: Full 3D printer status (Klipper printer/objects/query) === + - platform: rest + name: printer_3d_sensor + unique_id: "192.168.2.313a0c25fa-297d-4c19-b03c-ddf04840682b" + icon: mdi:printer-3d-nozzle + resource: "http://192.168.2.31:7125/printer/objects/query?heater_bed&extruder&print_stats&toolhead&display_status&virtual_sdcard&gcode_move&filament_motion_sensor%20btt_smart_filament&temperature_sensor%20Chamber_Temp" + json_attributes_path: "$.result.status" + json_attributes: + - heater_bed + - extruder + - print_stats + - toolhead + - display_status + - virtual_sdcard + - gcode_move + - "filament_motion_sensor btt_smart_filament_sensor" + - "temperature_sensor Chamber_Temp" + value_template: "OK" + force_update: true + scan_interval: 1 + + # === REST sensor: Basic printer state and message === + - platform: rest + name: printer_3d_info + unique_id: "192.168.2.311cba6677-02bd-4273-9083-b8301bf6943b" + icon: mdi:information-outline + scan_interval: 1 + resource_template: "http://192.168.2.31:7125/printer/info" + json_attributes_path: "$.result" + json_attributes: + - state_message + - state + value_template: "OK" + + # === REST sensor: Server configuration details (e.g., printer name) === + - platform: rest + name: printer_3d_server + unique_id: "192.168.2.311cba6677-02bd-4273-9083-b8301bf6949" + icon: mdi:server + scan_interval: 1 + resource_template: "http://192.168.2.31:7125/server/database/item?namespace=mainsail&key=general" + json_attributes_path: "$.result.value" + json_attributes: + - printername + value_template: "OK" diff --git a/templates/moonraker_3dprinter.yaml b/templates/moonraker_3dprinter.yaml new file mode 100644 index 0000000..cfb60db --- /dev/null +++ b/templates/moonraker_3dprinter.yaml @@ -0,0 +1,308 @@ +- binary_sensor: + - name: 3D Printer (K1C) Filament + unique_id: "192.168.2.315ce32fc9-5e95-49e7-80e7-bfdd2cf1d1fd" + device_class: motion + state: > + {% set attr = states.sensor.printer_3d_sensor.attributes.get("filament_switch_sensor Filament") %} + {{ attr.filament_detected if attr is defined else false }} + icon: mdi:printer-3d-nozzle-alert + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Filament Detected" + +- sensor: + - name: 3D Printer (K1C) Printer Name + unique_id: "192.168.2.313a0f3144-a801-422f-adb6-e2ed35796074" + state: '{{ states.sensor.printer_3d_server.attributes["printername"] }}' + availability: > + {% set items = ['sensor.printer_3d_server'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + icon: mdi:printer-3d + attributes: + friendly_name: "Printer Name" + + # === Sensor: Chamber temperature (actual) === + - name: 3D Printer (K1C) Chamber Temp + unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f741" + state: '{{ states.sensor.printer_3d_sensor.attributes["temperature_sensor Chamber_Temp"]["temperature"] | float(0) | round(1) }}' + unit_of_measurement: "°C" + icon: mdi:thermometer + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable'])|list|count == items|count }} + attributes: + friendly_name: "Chamber Actual" + + # === Sensor: Hotend target temperature === + - name: 3D Printer (K1C) Hotend Target + unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f740" + state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["target"] | float(0) | round(1) }}' + unit_of_measurement: "°C" + icon: mdi:thermometer + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable'])|list|count == items|count }} + attributes: + friendly_name: "Hotend Target" + + # === Sensor: Hotend actual temperature === + - name: 3D Printer (K1C) Hotend Actual + unique_id: "192.168.2.317c2593fb-a7dd-4ed7-a865-2e4dddddbb40" + state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["temperature"] | float(0) | round(1) }}' + unit_of_measurement: "°C" + icon: mdi:thermometer + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable'])|list|count == items|count }} + attributes: + friendly_name: "Hotend Actual" + + - name: 3D Printer (K1C) Hotend Power + unique_id: "192.168.2.31c57a1e35-92fa-403e-b3cf-ec1e97ef94cf" + state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["power"] | float(0) | round(3) * 100}}' + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) + |list|count == items|count }} + unit_of_measurement: "%" + icon: mdi:flash + attributes: + friendly_name: "Hotend Power" + + - name: 3D Printer (K1C) Bed Target + unique_id: "192.168.2.31eadec415-c281-4814-8fba-17c6c42670ec" + state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["target"] | float(0) | round(1) }}' + unit_of_measurement: "°C" + icon: mdi:thermometer + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Bed Target" + + - name: 3D Printer (K1C) Bed Actual + unique_id: "192.168.2.31cb33503c-c5d4-4e06-b79b-c1cd64ca2d7a" + state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["temperature"] | float(0) | round(1) }}' + unit_of_measurement: "°C" + icon: mdi:thermometer + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Bed Actual" + + - name: 3D Printer (K1C) Bed Power + unique_id: "192.168.2.31abb2fc5b-8173-4131-a942-fb11e30f4efa" + state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["power"] | float(0) | round(3) * 100 }}' + unit_of_measurement: "%" + icon: mdi:flash + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items)|rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Bed Power" + + - name: 3D Printer (K1C) Printer State + unique_id: "192.168.2.31758ce84c-3210-4f29-b6b3-38139180de96" + state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] }}' + icon: > + {% set val = states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] %} + {% if val == 'standby' %} + mdi:sleep + {% elif val == 'error' %} + mdi:alert-circle + {% elif val == 'printing' %} + mdi:printer-3d-nozzle + {% elif val == 'paused' %} + mdi:pause-circle + {% elif val == 'complete' %} + mdi:printer-3d + {% else %} + mdi:help-circle + {% endif %} + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state', 'in', ['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Printer State" + + - name: 3D Printer (K1C) Current Print + unique_id: "192.168.2.313a0f3144-a801-422f-adb6-e2ed35796072" + state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["filename"] }}' + icon: mdi:file + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state', 'in', ['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Current Print" + + - name: 3D Printer (K1C) Current Progress + unique_id: "192.168.2.318ec7163b-be00-4a10-8051-48cf9a260a29" + state: '{{ ((states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]) * 100) | round(0, "floor") }}' + unit_of_measurement: "%" + icon: mdi:progress-clock + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state', 'in', ['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Progress" + + - name: 3D Printer (K1C) Print time + unique_id: "192.168.2.31e1ac0fac-e8ba-4e05-8fa0-c8d8076f9f63" + state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] | timestamp_custom("%H:%M:%S", 0) }}' + icon: mdi:camera-timer + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state', 'in', ['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Time Elapsed" + + - name: 3D Printer (K1C) Time Remaining + unique_id: "192.168.2.31e12c8def-5ebe-43a4-9f75-605a0c46fc0f" + state: > + {{ + ( + ( + states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] + / states.sensor.printer_3d_sensor.attributes["display_status"]["progress"] + - states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] + ) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"] > 0 else 0 + ) | timestamp_custom("%H:%M:%S", 0) + }} + icon: mdi:timer-sand + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Time Remaining" + + - name: 3d_printer_eta + unique_id: "192.168.2.31a2b57068-9a32-4d2c-8cc9-57d2389a9082" + state: > + {{ + ( + as_timestamp(now()) + + ( + ( + states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] + / states.sensor.printer_3d_sensor.attributes["display_status"]["progress"] + - states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] + ) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"] > 0 else 0 + ) + ) | timestamp_custom("%H:%M:%S", 1) + }} + icon: mdi:av-timer + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "ETA" + + - name: 3D Printer (K1C) Message + unique_id: "192.168.2.310c418c0d-e59e-4d4e-aa11-8fae53df58f8" + state: '{{ states.sensor.printer_3d_sensor.attributes["display_status"]["message"] }}' + icon: mdi:message-cog + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Message" + + - name: 3D Printer (K1C) Layer Height + unique_id: "192.168.2.316cca455d-c327-4567-b886-4d7f99714265" + state: '{{ states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float(0) }}' + unit_of_measurement: "mm" + icon: mdi:arrow-collapse-down + availability: > + {% set items = ['sensor.printer_3d_file_metadata'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Layer Height" + + - name: 3D Printer (K1C) Object Height + unique_id: "192.168.2.316d6d9dc0-9a02-4ce4-a797-c84b42e011a6" + state: '{{ (states.sensor.printer_3d_file_metadata.attributes["object_height"] | float(0)) - (states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float(0)) }}' + unit_of_measurement: "mm" + icon: mdi:arrow-expand-vertical + availability: > + {% set items = ['sensor.printer_3d_file_metadata'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Object Height" + + - name: 3D Printer (K1C) Current Height + unique_id: "192.168.2.31d440e568-d4d1-4b3f-85c4-fdacd68c0e1a" + state: '{{ states.sensor.printer_3d_sensor.attributes["gcode_move"]["gcode_position"][2] | float(0) | round(2) }}' + unit_of_measurement: "mm" + icon: mdi:arrow-collapse-down + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Current Height" + + - name: 3D Printer (K1C) Current Layer + unique_id: "192.168.2.316a77acc1-8134-4354-b2f6-390adab81993" + state: '{{ (states("sensor.3d_printer_current_height") | float(0) / states("sensor.3d_printer_layer_height") | float(0)) | round(0) }}' + icon: mdi:counter + availability: > + {% set items = ['sensor.3d_printer_current_height','sensor.3d_printer_layer_height'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Current Layer" + + - name: 3D Printer (K1C) Total Layers + unique_id: "192.168.2.3153cfe906-28ec-44cd-926a-b08ffb8766e5" + state: '{{ (states("sensor.3d_printer_object_height") | float(0) / states("sensor.3d_printer_layer_height") | float(0)) | round(0) }}' + icon: mdi:counter + availability: > + {% set items = ['sensor.3d_printer_object_height','sensor.3d_printer_layer_height'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Total Layers" + + - name: 3D Printer (K1C) Actual Layer + unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f742" + state: '{{ states.sensor.printer_3d_sensor.attributes.print_stats["info"]["current_layer"] }} / {{ states.sensor.printer_3d_sensor.attributes.print_stats["info"]["total_layer"] }}' + icon: mdi:layers-triple + availability: > + {% set items = ['sensor.printer_3d_sensor'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Actual Layer" + + - name: 3D Printer (K1C) Object Thumbnails + unique_id: "192.168.2.3159b37837-b751-4d31-98c2-516a52edf833" + state: > + {% set dir = states('sensor.3d_printer_current_print') %} + {% set thumb = state_attr('sensor.printer_3d_file_metadata','thumbnails') %} + {% set img = (thumb | last).relative_path if thumb else 'not available' %} + {{ (dir.split('/')[:-1] + [img]) | join('/') }} + icon: mdi:image + availability: > + {% set items = ['sensor.printer_3d_file_metadata'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Object Thumbnails" + + - name: 3D Printer (K1C) State Message + unique_id: "192.168.2.319a5184c9-ac5b-44a9-a691-2b67c243d197" + state: '{{ states.sensor.printer_3d_info.attributes["state_message"] }}' + icon: mdi:message-cog + availability: > + {% set items = ['sensor.printer_3d_info'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "State Message" + + - name: 3D Printer (K1C) Bed and Nozzle Power + unique_id: "192.168.2.313988e9be-c910-4634-8205-38d53170d5a5" + state: '{{ states("sensor.3d_printer_bed_power") | float(0) | round(1) }}% / {{ states("sensor.3d_printer_hotend_power") | float(0) | round(1) }}%' + icon: mdi:meter-electric-outline + availability: > + {% set items = ['sensor.3d_printer_bed_power','sensor.3d_printer_hotend_power'] %} + {{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }} + attributes: + friendly_name: "Bed and Nozzle Power"