Skip to content

Instantly share code, notes, and snippets.

@malinovsku
Created August 11, 2023 06:38
Show Gist options
  • Save malinovsku/9f157a95f1da5d6abc2859580eee1bcf to your computer and use it in GitHub Desktop.
Save malinovsku/9f157a95f1da5d6abc2859580eee1bcf to your computer and use it in GitHub Desktop.
BK socket
substitutions:
device_name: kyxna-blok-5v
entity_name: kyxna_blok_5v
entity_friendly_name: kyxna blok 5v
device_name_wifi: kyxnablok5v
switch_dop_name: ''
switch_restore_mode: RESTORE_DEFAULT_ON
integration_method: trapezoid
switch_icon: "mdi:power-socket-eu"
switch_device_class: outlet
voltage_divider: "761"
current_resistor: "0.001028"
pin_button_inverted: 'true'
pin_switch_snv: P26
pin_led: P8
pin_button: P11
pin_sel: P24
pin_cf: P7
pin_cf1: P6
web_server:
port: 80
preferences:
flash_write_interval: 30s
esphome:
name: ${device_name}
libretiny:
board: generic-bk7231n-qfn32-tuya
framework:
version: dev
logger:
api:
encryption:
key: 000
ota:
password: 000
wifi:
ssid: 000
password: 000
fast_connect: on
ap:
ssid: ${device_name_wifi}
password: 000
button:
- platform: restart
name: ${entity_friendly_name} restart esp
entity_category: diagnostic
text_sensor:
- platform: template
name: ${entity_friendly_name} uptime esp
id: uptime_esp
icon: mdi:clock-start
entity_category: diagnostic
switch:
- platform: gpio
name: ${entity_friendly_name}${switch_dop_name}
id: switch_pub
pin: ${pin_switch_snv}
restore_mode: ${switch_restore_mode}
icon: ${switch_icon}
device_class: ${switch_device_class}
on_turn_on:
- script.execute: turn_lights
on_turn_off:
- script.execute: turn_lights
binary_sensor:
- platform: status
name: ${entity_friendly_name} status esp
entity_category: diagnostic
- platform: gpio
name: ${entity_friendly_name} button
id: button_short
disabled_by_default: true
filters:
- delayed_on: 80ms
pin:
number: ${pin_button}
inverted: ${pin_button_inverted}
on_click:
- min_length: 80ms
max_length: 2500ms
then:
- switch.toggle: switch_pub
- homeassistant.service:
service: logbook.log
data:
name: ${entity_friendly_name}
message: 🧩 нажата кнопка
entity_id: switch.${entity_name}
domain: switch
output:
- platform: gpio
id: state_led
pin:
number: ${pin_led}
inverted: true
light:
- platform: binary
output: state_led
id: switch_led
restore_mode: ${switch_restore_mode}
interval:
- interval: 1min
then:
- script.execute: turn_lights
script:
- id: turn_lights
mode: restart
then:
- delay: 20ms
- if:
condition:
switch.is_on: switch_pub
then:
- light.turn_on: switch_led
else:
- light.turn_off: switch_led
time:
- platform: sntp
id: my_time
sensor:
- platform: wifi_signal
name: ${entity_friendly_name} wifi signal esp
update_interval: 60s
entity_category: diagnostic
- platform: uptime
id: uptime_sensor
update_interval: 5min
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_esp
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(String(minutes) + "m")
).c_str();
- platform: integration
sensor: power
id: total_energy
name: ${entity_friendly_name} energy
device_class: energy
state_class: total_increasing
time_unit: h
restore: true
accuracy_decimals: 2
integration_method: ${integration_method}
- platform: total_daily_energy
power_id: power
device_class: energy
name: ${entity_friendly_name} daily energy
state_class: total_increasing
restore: true
id: daily_energy
method: ${integration_method}
- platform: hlw8012
model: BL0937
current_resistor: ${current_resistor}
voltage_divider: ${voltage_divider}
change_mode_every: 2
update_interval: 3s
sel_pin:
number: ${pin_sel}
inverted: true
cf_pin:
number: ${pin_cf}
inverted: true
mode:
input: true
pulldown: true
cf1_pin:
number: ${pin_cf1}
inverted: true
mode:
input: true
pulldown: true
current:
name: ${entity_friendly_name} current
unit_of_measurement: A
device_class: current
state_class: measurement
id: current
accuracy_decimals: 2
filters:
- throttle: 1s
- debounce: 1s
- delta: 0.09
voltage:
name: ${entity_friendly_name} voltage
unit_of_measurement: V
id: voltage
accuracy_decimals: 2
filters:
- throttle: 1s
- debounce: 1s
- delta: 3.0
power:
name: ${entity_friendly_name} power
unit_of_measurement: W
device_class: power
state_class: measurement
id: power
accuracy_decimals: 2
filters:
- throttle: 1s
- debounce: 1s
- delta: 0.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment