Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
Blog
-
Chia sẻ- YAML Dashboard HomeAssistant của TranBach
Các addon cần cài trên HACS
* Bubble Card
* Sunsink-power-flow-card
* Number-box
* Flexible Horseshoe card
Ngoài ra còn cần một số biến trợ giúp để hỗ trợ hiển thị, cái này các bạn tự tìm hiểu. Không dùng được kiểu của mình các bạn đọc tài liệu có thể tự custom kiểu khác cho chính bạn. bởi vì thực thể trong home assistant không ai giống ai.Dưới đây là code YAML Dashboard
title: Solar Mobi cards: [] visible: - user: 24ebe9c3cd5b46e38c4e0b67e26bbf7a - user: 045ec7a8ea5a449b8ac9a6fd8742cbb1 - user: a12b7ed30ec448c0b17d1ac04c3e1886 icon: mdi:cellphone type: sections sections: - type: grid cards: - type: custom:sunsynk-power-flow-card cardstyle: full show_solar: true battery: shutdown_soc: 15 show_daily: true shutdown_soc_offgrid: 14 linear_gradient: false dynamic_colour: false animate: false show_remaining_energy: true invert_power: true auto_scale: false show_absolute: true colour: - 57 - 210 - 15 charge_colour: - 70 - 197 - 2 energy: 6240 hide_soc: true count: 2 solar: show_daily: true mppts: 2 max_power: 6300 auto_scale: false dynamic_colour: true display_mode: 2 pv1_max_power: 3150 pv2_max_power: 3150 load: show_daily: true dynamic_colour: false essential_name: Nhà dynamic_icon: true colour: - 28 - 167 - 227 auto_scale: false label_daily_load: Tiêu thụ grid: show_daily_buy: true show_daily_sell: true show_nonessential: false grid_name: EVN label_daily_grid_buy: Mua về auto_scale: false invert_grid: false label_daily_grid_sell: Đẩy lưới no_grid_colour: - 145 - 145 - 145 colour: - 219 - 15 - 15 grid_off_colour: - 135 - 135 - 135 show_absolute: true entities: use_timer_248: switch.esp_inverter_toggle_system_timer priority_load_243: switch.esp_inverter_toggle_priority_load inverter_voltage_154: sensor.esp_inverter_inverter_voltage inverter_current_164: sensor.esp_inverter_inverter_current inverter_power_175: sensor.esp_inverter_inverter_power grid_connected_status_194: binary_sensor.esp_inverter_grid_connected_status inverter_status_59: sensor.esp_inverter_overall_state day_battery_charge_70: sensor.esp_inverter_day_battery_charge day_battery_discharge_71: sensor.esp_inverter_day_battery_discharge battery_voltage_183: sensor.jk_bms_total_voltage battery_power_190: sensor.jk_bms_power battery_current_191: sensor.jk_bms_current grid_power_169: sensor.esp_inverter_grid_power day_grid_import_76: sensor.esp_inverter_day_grid_import day_grid_export_77: sensor.esp_inverter_day_grid_export grid_ct_power_172: sensor.esp_inverter_grid_ct_power essential_power: sensor.esp_inverter_essential_power_1 nonessential_power: sensor.esp_inverter_nonessential_power aux_power_166: sensor.esp_inverter_aux_power day_pv_energy_108: sensor.esp_inverter_day_pv_energy pv1_power_186: sensor.esp_inverter_pv1_power pv2_power_187: sensor.esp_inverter_pv2_power pv1_voltage_109: sensor.esp_inverter_pv1_voltage pv1_current_110: sensor.esp_inverter_pv1_current pv2_voltage_111: sensor.esp_inverter_pv2_voltage pv2_current_112: sensor.esp_inverter_pv2_current battery_temp_182: sensor.jk_bms_power_tube_temperature load_frequency_192: sensor.esp_inverter_grid_frequency dc_transformer_temp_90: sensor.esp_inverter_dc_transformer_temperature radiator_temp_91: sensor.esp_inverter_radiator_temperature prog1_time: sensor.esp_inverter_prog1_time prog1_capacity: number.esp_inverter_prog1_capacity day_load_energy_84: sensor.tong_tieu_thu load_power_L1: sensor.esp_inverter_load_l1_power grid_voltage: sensor.esp_inverter_grid_voltage prog1_charge: switch.esp_inverter_prog1_grid_charge prog2_time: sensor.esp_inverter_prog2_time prog3_time: sensor.esp_inverter_prog3_time prog4_time: sensor.esp_inverter_prog4_time prog5_time: sensor.esp_inverter_prog5_time prog6_time: sensor.esp_inverter_prog6_time prog6_charge: switch.esp_inverter_prog6_grid_charge prog6_capacity: number.esp_inverter_prog6_capacity prog5_capacity: number.esp_inverter_prog5_capacity prog4_capacity: number.esp_inverter_prog4_capacity prog3_capacity: number.esp_inverter_prog3_capacity prog2_capacity: number.esp_inverter_prog2_capacity prog2_charge: switch.esp_inverter_prog2_grid_charge prog3_charge: switch.esp_inverter_prog3_grid_charge prog4_charge: switch.esp_inverter_prog4_grid_charge prog5_charge: switch.esp_inverter_prog5_grid_charge grid_ct_power_total: sensor.esp_inverter_grid_ct_power remaining_solar: sensor.energy_production_today_remaining environment_temp: sensor.cam_bien_nhiet_do_2_nhi_t battery2_soc_184: sensor.jk_130_state_of_charge battery_soc_184: sensor.jk_bms_state_of_charge battery2_rated_capacity: sensor.jk_130_capacity_remaining battery_rated_capacity: sensor.jk_bms_capacity_remaining battery2_power_190: sensor.jk_130_power battery2_current_191: sensor.jk_130_current battery2_temp_182: sensor.jk_130_power_tube_temperature battery2_voltage_183: sensor.jk_130_total_voltage large_font: true panel_mode: true show_battery: true show_grid: true max_line_width: 20 min_line_width: 3 inverter: modern: false three_phase: false auto_scale: false autarky: power model: ces-battery-box title_colour: - 168 - 52 - 52 title_size: "8" decimal_places: 0 dynamic_line_width: false decimal_places_energy: 1 wide: true grid_options: columns: 36 rows: auto battery2: energy: 13400 shutdown_soc: 15 shutdown_soc_offgrid: 20 colour: - 240 - 178 - 92 charge_colour: - 240 - 199 - 51 invert_power: true show_absolute: true dynamic_colour: false animate: false linear_gradient: false - type: vertical-stack cards: - type: markdown content: >+ <ha-alert alert-type="info" title="Đến thời điểm này">*Sản lượng* điện hôm nay là **{{ states('sensor.esp_inverter_day_pv_energy') }}**/**{{ states('sensor.energy_production_today') | float | round(1) }}** kWh dự báo. *Tổng tiêu thụ* là **{{ states('sensor.tong_tieu_thu') | float | round(1)}}** kWh, trong đó: Tự dùng 🔅 | **{{ states('sensor.tu_su_dung') | float | round(2) }}** | **{{ states('sensor.tu_dung_thang') | float | round(2) }}** Sạc Pin ⚡️| **{{ states('sensor.esp_inverter_day_battery_charge') }}** | **{{ states('sensor.sac_pin_thang') | float | round(2) }}** Xả Pin 🪫 | **{{ states('sensor.esp_inverter_day_battery_discharge') | float | round(2) }}** | **{{ states('sensor.xa_pin_thang') | float | round(2) }}** Mua về 💲 | **{{ states('sensor.esp_inverter_day_grid_import') }}** | **{{ states('sensor.dien_mua_evn_ch') | float | round(2) }}** - type: markdown content: >- <ha-alert alert-type="success">Bạn phải trả **{{ states('sensor.hien_thi_tien_wo_solar') }} VNĐ** ({{states('sensor.tong_tieu_thu_thang_ct2') }} kWh) cho EVN nếu không tự sản xuất được sản lượng trị giá **{{ states('sensor.hien_thi_tien') }} VNĐ** ({{states('sensor.tu_dung_xa_pin') }} kWh) Hiện tại bạn phải *trả EVN* tạm tính là **{{ states('sensor.hien_thi_tien_evn') }} VNĐ** (*TH:* **{{ states('sensor.pc10mm0900203_ecost_monthly_new') }} VNĐ** {{states('sensor.dien_mua_evn_th') | float | round(1) }} kWh | *CH:* **{{ states('sensor.pc10mm0965997_ecost_monthly_new') }} VNĐ** {{states('sensor.dien_mua_evn_ch') | float | round(1) }} kWh) Dự báo *hôm nay còn lại* **{{ states('sensor.energy_production_today_remaining') | float | round(1) }}** kW và *ngày mai* sản lượng đạt được **{{ states('sensor.energy_production_tomorrow') | float | round(1) }}** kWh </ha-alert> grid_options: columns: 12 rows: auto - type: vertical-stack cards: - type: custom:apexcharts-card experimental: color_threshold: true brush: true graph_span: 3h brush: selection_span: 30m apex_config: null series: - entity: sensor.tong_pv color: blue type: area stroke_width: 1 color_threshold: - value: 4000 color: red - value: 2500 color: yellow - value: 1500 color: green - entity: sensor.tong_pv color: red stroke_width: 1 float_precision: 0 show: in_brush: true in_chart: false update_interval: 10s visibility: - condition: numeric_state entity: sensor.tong_pv above: 50 column_span: 2 - type: grid cards: - type: custom:weather-chart-card entity: weather.forecast_nha show_main: false show_temperature: false show_current_condition: false show_attributes: false show_time: false show_time_seconds: false show_day: false show_date: false show_humidity: false show_pressure: false show_wind_direction: false show_wind_speed: false show_sun: false show_feels_like: false show_dew_point: false show_wind_gust_speed: false show_visibility: false show_last_changed: false use_12hour_format: false icons_size: "50" animated_icons: true icon_style: style1 autoscroll: false forecast: precipitation_type: rainfall show_probability: false labels_font_size: "11" precip_bar_size: "100" style: style2 show_wind_forecast: true condition_icons: true round_temp: false type: daily number_of_forecasts: "0" disable_animation: true units: speed: "" humid: sensor.cam_bien_nhiet_do_2_m temp: sensor.cam_bien_nhiet_do_2_nhi_t - type: vertical-stack cards: - type: vertical-stack cards: - type: horizontal-stack cards: - type: custom:flex-horseshoe-card view_layout: grid-area: g2 entities: - entity: sensor.tong_pv decimals: 0 unit: W icon: false name: PV - entity: sensor.esp_inverter_day_pv_energy decimals: 1 unit: SL - entity: sensor.energy_production_today_remaining decimals: 1 unit: Còn - entity: input_text.trang_thai_solar decimals: 0 show: horseshoe_style: lineargradient layout: vlines: - id: 0 xpos: 50 ypos: 60 length: 5 styles: - opacity: 0.2; states: - id: 0 entity_index: 0 xpos: 50 ypos: 80 styles: - font-size: 2em; - opacity: 0.9; - id: 1 entity_index: 1 xpos: 44 ypos: 63 styles: - font-size: 1.3em; - text-anchor: end; - id: 2 entity_index: 2 xpos: 55 ypos: 63 styles: - text-anchor: start; - font-size: 1.3em; - id: 3 entity_index: 3 xpos: 50 ypos: 48 styles: - font-size: 5em; names: - id: 0 entity_index: 0 xpos: 50 ypos: 95 styles: - font-size: 1.2em; horseshoe_scale: min: 0 max: 6500 width: 15 color_stops: "10": green "6500": orange card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: custom:flex-horseshoe-card view_layout: grid-area: g2 entities: - entity: sensor.abs_grid_power decimals: 0 icon: mdi:transmission-tower unit: W name: Lưới - entity: input_text.trang_thai_luoi decimals: 0 - entity: sensor.esp_inverter_inverter_voltage decimals: 0 unit: ÁP - entity: sensor.esp_inverter_day_grid_import decimals: 1 unit: mua show: horseshoe_style: lineargradient layout: states: - id: 0 entity_index: 0 xpos: 50 ypos: 80 styles: - font-size: 2em; - opacity: 0.9; - id: 1 entity_index: 1 xpos: 50 ypos: 21 styles: - font-size: 1em; - id: 2 entity_index: 2 xpos: 35 ypos: 63 styles: - font-size: 1.3em; - id: 3 entity_index: 3 xpos: 65 ypos: 63 styles: - font-size: 1.3em; names: - id: 0 entity_index: 0 xpos: 50 ypos: 95 styles: - font-size: 1.2em; icons: - id: 0 entity_index: 0 xpos: 50 ypos: 45 icon_size: 6 styles: - color: rgb(235, 79, 52); horseshoe_scale: min: 0 max: 6500 width: 15 color_stops: "10": green "6500": orange card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } visibility: - condition: state entity: binary_sensor.esp_inverter_grid_connected_status state: "on" - type: custom:flex-horseshoe-card view_layout: grid-area: g2 entities: - entity: sensor.abs_grid_power decimals: 0 icon: mdi:transmission-tower-off unit: W name: OFF GRID - entity: input_text.trang_thai_luoi decimals: 0 - entity: binary_sensor.esp_inverter_grid_connected_status decimals: 2 unit: EVN - entity: sensor.esp_inverter_inverter_voltage decimals: 0 unit: ÁP - entity: sensor.esp_inverter_day_grid_import decimals: 1 unit: mua show: horseshoe_style: lineargradient layout: states: - id: 0 entity_index: 0 xpos: 50 ypos: 80 styles: - font-size: 2em; - opacity: 0.9; - id: 1 entity_index: 1 xpos: 35 ypos: 200 styles: - font-size: 2em; - id: 2 entity_index: 2 xpos: 35 ypos: 63 styles: - font-size: 1.3em; - id: 3 entity_index: 3 xpos: 250 ypos: 63 styles: - font-size: 1.3em; - id: 4 entity_index: 4 xpos: 65 ypos: 63 styles: - font-size: 1.3em; names: - id: 0 entity_index: 0 xpos: 50 ypos: 95 styles: - font-size: 1.2em; - id: 1 entity_index: 0 xpos: 50 ypos: 95 styles: - font-size: 1.2em; icons: - id: 0 entity_index: 0 xpos: 50 ypos: 45 icon_size: 6 styles: - color: gray; horseshoe_scale: min: 0 max: 6500 width: 15 color_stops: "10": gray "6500": gray card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } visibility: - condition: state entity: binary_sensor.esp_inverter_grid_connected_status state: "off" - type: horizontal-stack cards: - type: custom:flex-horseshoe-card view_layout: grid-area: g2 entities: - entity: sensor.abs_battery decimals: 0 unit: W name: PIN - entity: sensor.esp_inverter_day_battery_charge decimals: 1 unit: SẠC - entity: sensor.esp_inverter_battery_voltage decimals: 1 - entity: sensor.soc_giao_tiep decimals: 0 - entity: input_text.trang_thai_pin decimals: 0 - entity: sensor.esp_inverter_battery_soc decimals: 0 - entity: sensor.jk_130_state_of_charge decimals: 0 show: horseshoe_style: lineargradient layout: vlines: - id: 0 xpos: 50 ypos: 60 length: 5 styles: - opacity: 0.2; states: - id: 0 entity_index: 0 xpos: 50 ypos: 80 styles: - font-size: 2em; - opacity: 0.9; - id: 1 entity_index: 1 xpos: 44 ypos: 63 styles: - font-size: 1.3em; - text-anchor: end; - id: 2 entity_index: 2 xpos: 55 ypos: 63 styles: - text-anchor: start; - font-size: 1.3em; - id: 3 entity_index: 3 xpos: 50 ypos: 18 styles: - font-size: 1.5em; - id: 4 entity_index: 4 xpos: 50 ypos: 48 styles: - font-size: 5em; - id: 5 entity_index: 5 xpos: 35 ypos: 45 styles: - font-size: 1.3em; - text-anchor: end; - id: 6 entity_index: 6 xpos: 65 ypos: 45 styles: - text-anchor: start; - font-size: 1.3em; names: - id: 0 entity_index: 0 xpos: 50 ypos: 95 styles: - font-size: 1.2em; icons: - id: 0 entity_index: 0 xpos: 50 ypos: 45 icon_size: 6 styles: - color: rgb(105, 242, 31); horseshoe_scale: min: 0 max: 6500 width: 15 color_stops: "10": green "6500": orange card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: custom:flex-horseshoe-card view_layout: grid-area: g2 entities: - entity: sensor.esp_inverter_load_power decimals: 0 icon: mdi:home-roof unit: W name: TẢI - entity: sensor.esp_inverter_day_battery_discharge decimals: 1 unit: XẢ - entity: sensor.tong_tieu_thu decimals: 1 unit: TỔNG - entity: input_text.trang_thai_load decimals: 0 show: horseshoe_style: lineargradient layout: vlines: - id: 0 xpos: 50 ypos: 60 length: 5 styles: - opacity: 0.2; states: - id: 0 entity_index: 0 xpos: 50 ypos: 80 styles: - font-size: 2em; - opacity: 0.9; - id: 1 entity_index: 1 xpos: 35 ypos: 63 styles: - font-size: 1.3em; - id: 2 entity_index: 2 xpos: 55 ypos: 63 styles: - text-anchor: start; - font-size: 1.3em; - id: 3 entity_index: 3 xpos: 50 ypos: 48 styles: - font-size: 3em; names: - id: 0 entity_index: 0 xpos: 50 ypos: 95 styles: - font-size: 1.2em; icons: - id: 0 entity_index: 0 xpos: 50 ypos: 35 icon_size: 7 horseshoe_scale: min: 0 max: 6500 width: 15 color_stops: "10": green "6500": orange card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: custom:vertical-stack-in-card cards: - type: custom:local-conditional-card id: pin1 default: show card: type: vertical-stack cards: - type: custom:paper-buttons-row styles: border-radius: 28px justify-content: center width: max-content margin: 10px auto 12px auto buttons: - layout: name name: Pin Tổng Quan tap_action: action: fire-dom-event local_conditional_card: action: set ids: - pin1: show - pin2: hide styles: name: color: black padding: 0 22px 0 button: background: orange border-radius: 28px height: 24px display: flex - layout: name name: Cell Pin tap_action: action: fire-dom-event local_conditional_card: action: set ids: - pin1: hide - pin2: show styles: name: color: black padding: 0 22px 0 button: background: none border-radius: 28px height: 24px display: flex - type: vertical-stack cards: - type: custom:bubble-card card_type: button button_type: state card_layout: large-1-rows name: Pack 280 icon: mdi:battery-charging show_state: true button_action: tap_action: action: navigate navigation_path: "#energy" sub_button: - icon: mdi:lightning-bolt-outline show_background: false show_state: true entity: sensor.jk_bms_current - entity: sensor.jk_bms_delta_cell_voltage show_background: false show_state: true icon: mdi:delta - show_state: true show_background: false icon: mdi:battery-charging-90 entity: sensor.jk_bms_state_of_charge styles: |- .bubble-button-card-container { background: rgba(27, 135, 207,0.8) !important; entity: sensor.jk_bms_total_voltage scrolling_effect: true show_icon: false - type: custom:bubble-card card_type: button button_type: state card_layout: large-1-rows name: Pack 130 icon: mdi:battery-charging show_state: true button_action: tap_action: action: navigate navigation_path: "#energy" sub_button: - icon: mdi:lightning-bolt-outline show_background: false show_state: true entity: sensor.jk_130_current - entity: sensor.jk_130_delta_cell_voltage show_background: false show_state: true icon: mdi:delta - show_state: true show_background: false icon: mdi:battery-charging-90 entity: sensor.jk_130_state_of_charge styles: |- .bubble-button-card-container { background: rgba(9, 79, 135,0.8) !important; entity: sensor.jk_130_total_voltage scrolling_effect: true show_icon: false - type: custom:local-conditional-card id: pin2 default: hide card: type: vertical-stack cards: - type: custom:paper-buttons-row styles: border-radius: 28px justify-content: center width: max-content margin: 10px auto 12px auto buttons: - layout: name name: Pin Tổng Quan tap_action: action: fire-dom-event local_conditional_card: action: set ids: - pin1: show - pin2: hide styles: name: color: black padding: 0 22px button: background: none border-radius: 28px height: 24px display: flex - layout: name name: Cell Pin tap_action: action: fire-dom-event local_conditional_card: action: set ids: - pin1: hide - pin2: show styles: name: color: black padding: 0 22px 0 button: background: orange border-radius: 28px height: 24px display: flex - type: vertical-stack cards: - type: horizontal-stack cards: - type: custom:button-card name: Cell Voltage Delta size: 25% entity: sensor.jk_bms_delta_cell_voltage show_icon: true show_name: true show_state: false show_label: true label: | [[[ return '280: ' + (states['sensor.jk_bms_delta_cell_voltage'] ? Number.parseFloat(states['sensor.jk_bms_delta_cell_voltage'].state).toFixed(3) + ' V' : 'N/A') + '<br>' + // Sử dụng <br> để xuống dòng '130: ' + (states['sensor.jk_130_delta_cell_voltage'] ? Number.parseFloat(states['sensor.jk_130_delta_cell_voltage'].state).toFixed(3) + ' V' : 'N/A'); ]]] icon: mdi:delta styles: icon: - color: | [[[ if (entity.state < 0.010) return 'darkgreen'; if (entity.state < 0.020) return 'darkorange'; else return 'red'; ]]] card: - font-size: 12px - height: 100px - padding: 10px - white-space: normal; - text-align: left; - type: custom:button-card name: Pack Voltage size: 25% entity: sensor.jk_bms_total_voltage show_icon: true show_name: true show_state: false show_label: true label: | [[[ return '280: ' + (states['sensor.jk_bms_total_voltage'] ? Number.parseFloat(states['sensor.jk_bms_total_voltage'].state).toFixed(2) + ' V' : 'N/A') + '<br>' + // Sử dụng <br> để xuống dòng '130: ' + (states['sensor.jk_130_total_voltage'] ? Number.parseFloat(states['sensor.jk_130_total_voltage'].state).toFixed(2) + ' V' : 'N/A'); ]]] icon: mdi:server styles: icon: - color: | [[[ if (entity.state > 48) return 'darkgreen'; if (entity.state > 52) return 'darkorange'; else return 'red'; ]]] card: - font-size: 12px - height: 100px - padding: 10px - white-space: normal; - text-align: left; - type: custom:button-card name: | [[[ if (entity.state < 0) return "Discharging"; else return "Charging"; ]]] size: 25% entity: sensor.jk_bms_power show_icon: true show_name: true show_state: false show_label: true label: | [[[ return '280: ' + (states['sensor.jk_bms_power'] ? Number.parseFloat(states['sensor.jk_bms_power'].state).toFixed(1) + ' W' : 'N/A') + '<br>' + // Sử dụng <br> để xuống dòng '130: ' + (states['sensor.jk_130_power'] ? Number.parseFloat(states['sensor.jk_130_power'].state).toFixed(1) + ' W' : 'N/A'); ]]] icon: | [[[ if (entity.state < 0) return "mdi:battery-arrow-down-outline"; else return "mdi:battery-arrow-up-outline"; ]]] styles: icon: - color: | [[[ if (entity.state > 5000) return 'darkred'; if (entity.state > 1000) return 'darkorange'; if (entity.state < -5000) return 'darkred'; if (entity.state < -1000) return 'darkorange'; else return 'darkgreen'; ]]] card: - font-size: 12px - height: 100px - padding: 10px - white-space: normal; - text-align: left; - type: horizontal-stack cards: - type: custom:button-card name: SOC size: 25% entity: sensor.jk_bms_state_of_charge show_icon: true show_name: true show_state: false show_label: true label: | [[[ return '280: ' + (states['sensor.jk_bms_state_of_charge'] ? Number.parseFloat(states['sensor.jk_bms_state_of_charge'].state).toFixed(1) + ' %' : 'N/A') + '<br>' + // Sử dụng <br> để xuống dòng '130: ' + (states['sensor.jk_130_state_of_charge'] ? Number.parseFloat(states['sensor.jk_130_state_of_charge'].state).toFixed(1) + ' %' : 'N/A'); ]]] icon: | [[[ if (entity.state > 90) return "mdi:battery"; if (entity.state > 80) return "mdi:battery-90"; if (entity.state > 70) return "mdi:battery-80"; if (entity.state > 60) return "mdi:battery-70"; if (entity.state > 50) return "mdi:battery-60"; if (entity.state > 40) return "mdi:battery-50"; if (entity.state > 30) return "mdi:battery-40"; if (entity.state > 20) return "mdi:battery-30"; if (entity.state > 10) return "mdi:battery-20"; else return "mdi:battery-alert-variant-outline"; ]]] styles: icon: - color: | [[[ if (entity.state > 30 ) return 'darkgreen'; if (entity.state > 15 ) return 'yellow'; else return 'red'; ]]] card: - font-size: 12px - height: 100px - padding: 10px - white-space: normal; - text-align: left; - type: custom:button-card name: Dung Lượng size: 25Ah entity: sensor.jk_bms_capacity_remaining show_icon: true show_name: true show_state: false show_label: true label: | [[[ return '280: ' + (states['sensor.jk_bms_capacity_remaining'] ? Number.parseFloat(states['sensor.jk_bms_capacity_remaining'].state).toFixed(0) + ' Ah' : 'N/A') + '<br>' + // Sử dụng <br> để xuống dòng '130: ' + (states['sensor.jk_130_capacity_remaining'] ? Number.parseFloat(states['sensor.jk_130_capacity_remaining'].state).toFixed(0) + ' Ah' : 'N/A'); ]]] icon: | [[[ if (entity.state > 99) return "mdi:check-circle"; if (entity.state > 95) return "mdi:alert-circle"; else return "mdi:cancel"; ]]] styles: icon: - color: | [[[ if (entity.state > 99) return 'darkgreen'; if (entity.state > 95) return 'darkorange'; else return 'red'; ]]] card: - font-size: 12px - height: 100px - padding: 10px - white-space: normal; - text-align: left; - type: custom:button-card name: | [[[ if (entity.state < 0) return "Discharging"; else return "Charging"; ]]] size: 25% entity: sensor.jk_bms_current show_icon: true show_name: true show_state: false show_label: true label: | [[[ return '280: ' + (states['sensor.jk_bms_current'] ? Number.parseFloat(states['sensor.jk_bms_current'].state).toFixed(1) + ' A' : 'N/A') + '<br>' + // Sử dụng <br> để xuống dòng '130: ' + (states['sensor.jk_130_current'] ? Number.parseFloat(states['sensor.jk_130_current'].state).toFixed(1) + ' A' : 'N/A'); ]]] icon: | [[[ if (entity.state < 0) return "mdi:battery-arrow-down-outline"; else return "mdi:battery-arrow-up-outline"; ]]] styles: icon: - color: | [[[ if (entity.state > 5000) return 'darkred'; if (entity.state > 1000) return 'darkorange'; if (entity.state < -5000) return 'darkred'; if (entity.state < -1000) return 'darkorange'; else return 'darkgreen'; ]]] card: - font-size: 12px - height: 100px - padding: 10px - white-space: normal; - text-align: left; - type: custom:bar-card direction: up columns: 8 decimal: 3 max: 3.45 min: 3 height: 80px severity: - color: darkred from: 3.45 to: 4 - color: darkorange from: 3.4 to: 3.45 - color: rgb(189, 164, 66) from: 3.1 to: 3.4 - color: darkred from: 2.5 to: 3.1 positions: icon: "off" indicator: inside name: outside card_mod: style: |- bar-card-value { margin-right: auto; margin-left: auto; margin-bottom: 35px; font-size: 10px; font-weight: normal; text-shadow: 1px 1px #0005; } bar-card-name { margin-right: auto; margin-left: auto; margin-bottom: 0px; font-size: 10px; font-weight: normal; text-shadow: 1px 1px #0005; } entities: - entity: sensor.jk_bms_cell_voltage_1 name: Cell 01 - entity: sensor.jk_bms_cell_voltage_2 name: Cell 02 - entity: sensor.jk_bms_cell_voltage_3 name: Cell 03 - entity: sensor.jk_bms_cell_voltage_4 name: Cell 04 - entity: sensor.jk_bms_cell_voltage_5 name: Cell 05 - entity: sensor.jk_bms_cell_voltage_6 name: Cell 06 - entity: sensor.jk_bms_cell_voltage_7 name: Cell 07 - entity: sensor.jk_bms_cell_voltage_8 name: Cell 08 - entity: sensor.jk_bms_cell_voltage_9 name: Cell 09 - entity: sensor.jk_bms_cell_voltage_10 name: Cell 10 - entity: sensor.jk_bms_cell_voltage_11 name: Cell 11 - entity: sensor.jk_bms_cell_voltage_12 name: Cell 12 - entity: sensor.jk_bms_cell_voltage_13 name: Cell 13 - entity: sensor.jk_bms_cell_voltage_14 name: Cell 14 - entity: sensor.jk_bms_cell_voltage_15 name: Cell 15 - entity: sensor.jk_bms_cell_voltage_16 name: Cell 16 - type: custom:bar-card direction: up columns: 8 decimal: 3 max: 3.45 min: 3 height: 80px severity: - color: darkred from: 3.45 to: 4 - color: darkorange from: 3.4 to: 3.45 - color: rgb(9, 122, 214) from: 3.1 to: 3.4 - color: darkred from: 2.5 to: 3.1 positions: icon: "off" indicator: inside name: outside card_mod: style: |- bar-card-value { margin-right: auto; margin-left: auto; margin-bottom: 35px; font-size: 10px; font-weight: normal; text-shadow: 1px 1px #0005; } bar-card-name { margin-right: auto; margin-left: auto; margin-bottom: 0px; font-size: 10px; font-weight: normal; text-shadow: 1px 1px #0005; } entities: - entity: sensor.jk_130_cell_voltage_1 name: Cell 01 - entity: sensor.jk_130_cell_voltage_2 name: Cell 02 - entity: sensor.jk_130_cell_voltage_3 name: Cell 03 - entity: sensor.jk_130_cell_voltage_4 name: Cell 04 - entity: sensor.jk_130_cell_voltage_5 name: Cell 05 - entity: sensor.jk_130_cell_voltage_6 name: Cell 06 - entity: sensor.jk_130_cell_voltage_7 name: Cell 07 - entity: sensor.jk_130_cell_voltage_8 name: Cell 08 - entity: sensor.jk_130_cell_voltage_9 name: Cell 09 - entity: sensor.jk_130_cell_voltage_10 name: Cell 10 - entity: sensor.jk_130_cell_voltage_11 name: Cell 11 - entity: sensor.jk_130_cell_voltage_12 name: Cell 12 - entity: sensor.jk_130_cell_voltage_13 name: Cell 13 - entity: sensor.jk_130_cell_voltage_14 name: Cell 14 - entity: sensor.jk_130_cell_voltage_15 name: Cell 15 - entity: sensor.jk_130_cell_voltage_16 name: Cell 16 card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: custom:slider-button-card entity: input_boolean.sac_nhanh slider: direction: left-right background: gradient use_state_color: true use_percentage_bg_opacity: false show_track: false toggle_on_click: true force_square: false show_attribute: false show_name: true show_state: false compact: true icon: show: true use_state_color: true tap_action: action: more-info icon: "" action_button: mode: toggle icon: mdi:power show: true show_spinner: true tap_action: action: toggle show_attribute: true - type: custom:bubble-card card_type: button entity: input_boolean.uu_tien_sac_khong_xa force_icon: false show_name: true show_state: false show_last_changed: false show_attribute: false tap_action: action: none sub_button: - entity: input_boolean.uu_tien_sac_khong_xa show_background: false show_icon: false show_name: false show_state: true show_last_changed: true - type: grid cards: - type: heading icon: mdi:meter-electric-outline heading_style: subtitle badges: - type: entity show_state: true show_icon: true entity: sensor.esp_inverter_dc_transformer_temperature icon: mdi:current-dc - type: entity show_state: true show_icon: false entity: input_text.temp_dc color: red - type: entity show_state: true show_icon: true entity: sensor.esp_inverter_radiator_temperature icon: mdi:current-ac - type: entity show_state: true show_icon: false entity: input_text.temp_ac - type: entity show_state: false show_icon: true entity: fan.fan_controller_12v_fan color: deep-orange visibility: - condition: state entity: fan.fan_controller_12v_fan state: "on" heading: Nhiệt độ Inverter - type: vertical-stack cards: - type: horizontal-stack cards: - type: custom:slider-button-card entity: media_player.lg_webos_smart_tv slider: direction: left-right background: gradient use_state_color: true use_percentage_bg_opacity: false show_track: true toggle_on_click: true force_square: false show_attribute: true attribute: media_title show_name: true show_state: true compact: false icon: show: true use_state_color: true tap_action: action: toggle icon: mdi:television action_button: mode: toggle icon: mdi:power show: true show_spinner: true tap_action: action: toggle show_attribute: true - type: custom:slider-button-card entity: switch.dung_evn_switch_1 slider: direction: left-right background: gradient use_state_color: true use_percentage_bg_opacity: false show_track: false toggle_on_click: true force_square: false show_attribute: false show_name: true show_state: false compact: false icon: show: true use_state_color: true tap_action: action: toggle icon: mdi:transmission-tower-import action_button: mode: toggle icon: mdi:power show: true show_spinner: true tap_action: action: toggle show_attribute: true name: Dùng CT2 - type: custom:slider-button-card entity: switch.may_bom_switch_1 slider: direction: left-right background: gradient use_state_color: true use_percentage_bg_opacity: false show_track: false toggle_on_click: true force_square: false show_attribute: false show_name: true show_state: false compact: false icon: show: true use_state_color: true tap_action: action: toggle icon: mdi:water-pump action_button: mode: toggle icon: mdi:power show: true show_spinner: true tap_action: action: toggle show_attribute: true name: Máy bơm - type: horizontal-stack cards: - type: custom:slider-button-card entity: switch.man_led_switch_1 slider: direction: left-right background: gradient use_state_color: true use_percentage_bg_opacity: false show_track: false toggle_on_click: true force_square: false show_attribute: false show_name: true show_state: false compact: false icon: show: true use_state_color: true tap_action: action: toggle icon: mdi:led-on action_button: mode: toggle icon: mdi:power show: true show_spinner: true tap_action: action: toggle show_attribute: true name: Màn hình LED - type: custom:slider-button-card entity: switch.led_50w_switch_1 slider: direction: left-right background: gradient use_state_color: true use_percentage_bg_opacity: false show_track: false toggle_on_click: true force_square: false show_attribute: false show_name: true show_state: false compact: false icon: show: true use_state_color: true tap_action: action: toggle icon: mdi:spotlight action_button: mode: toggle icon: mdi:power show: true show_spinner: true tap_action: action: toggle show_attribute: true name: Đèn LED sân - type: custom:slider-button-card entity: switch.tu_lanh_switch_1 slider: direction: left-right background: gradient use_state_color: true use_percentage_bg_opacity: false show_track: false toggle_on_click: true force_square: false show_attribute: false show_name: true show_state: false compact: false icon: show: true use_state_color: true tap_action: action: toggle icon: mdi:fridge action_button: mode: toggle icon: mdi:power show: true show_spinner: true tap_action: action: toggle show_attribute: true name: Tủ lạnh - type: vertical-stack cards: - type: horizontal-stack cards: - graph: line type: sensor entity: sensor.tong_pv detail: 2 name: Công suất PV theme: Metro Orange hours_to_show: 2 - graph: line type: sensor entity: sensor.esp_inverter_grid_ct_power detail: 2 name: Lưới EVN theme: Metro Red hours_to_show: 2 - type: horizontal-stack cards: - graph: line type: sensor entity: sensor.abs_battery detail: 2 name: Pin Đang Sạc theme: Metro Green hours_to_show: 2 visibility: - condition: numeric_state entity: sensor.esp_inverter_battery_power below: 0 icon: mdi:power-plug-battery-outline - graph: line type: sensor entity: sensor.esp_inverter_battery_power detail: 2 name: Pin Đang Xả theme: Metro Green hours_to_show: 2 visibility: - condition: numeric_state entity: sensor.esp_inverter_battery_power above: 0 - graph: line type: sensor entity: sensor.esp_inverter_load_power detail: 2 name: Tải nhà theme: Metro Blue hours_to_show: 2 visibility: - condition: state entity: input_boolean.5_giay_hien_thi state: "on" - type: vertical-stack cards: - type: horizontal-stack cards: - graph: line type: sensor entity: sensor.esp_inverter_day_pv_energy detail: 1 name: Sản lượng icon: mdi:solar-power unit: kWh theme: Metro Orange hours_to_show: 24 - graph: line type: sensor entity: sensor.esp_inverter_day_grid_import detail: 1 icon: mdi:transmission-tower theme: Metro Blue unit: kWh name: Điện mua hours_to_show: 24 - type: horizontal-stack cards: - graph: line type: sensor entity: sensor.esp_inverter_day_battery_charge detail: 1 name: Sạc pin icon: mdi:power-plug-battery-outline theme: Metro Green unit: kWh visibility: - condition: numeric_state entity: sensor.esp_inverter_battery_power below: 0 - graph: line type: sensor entity: sensor.esp_inverter_day_battery_discharge detail: 1 name: Xả pin icon: mdi:battery-minus-outline theme: Metro Green unit: kWh visibility: - condition: numeric_state entity: sensor.esp_inverter_battery_power above: 0 - graph: line type: sensor entity: sensor.tong_tieu_thu detail: 1 name: Tiêu thụ icon: mdi:home-lightbulb-outline theme: Metro Purple unit: kWh hours_to_show: 24 visibility: - condition: state entity: input_boolean.5_giay_hien_thi state: "off" - type: vertical-stack cards: - type: horizontal-stack cards: - graph: none type: sensor entity: sensor.than_tiet_kiem detail: 1 name: Than tiết kiệm icon: mdi:grill unit: Tấn theme: ios-dark-mode-dark-blue - graph: none type: sensor entity: sensor.co2_tiet_giam detail: 1 icon: mdi:molecule-co2 name: CO2 theme: ios-dark-mode-dark-blue unit: Tấn - type: horizontal-stack cards: - graph: none type: sensor entity: sensor.cay_xanh detail: 1 name: Cây xanh icon: mdi:forest-outline theme: ios-dark-mode-dark-blue unit: Cây - graph: none type: sensor entity: sensor.tien detail: 1 name: Gánh được icon: mdi:cash-100 theme: ios-dark-mode-dark-blue unit: Triệu đồng grid_options: columns: full - type: vertical-stack cards: - type: vertical-stack cards: - type: markdown content: " **{{ states('sensor.esp_inverter_time_slot_1') }} đến {{ states('sensor.esp_inverter_time_slot_2') }}**" card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: horizontal-stack cards: - type: custom:numberbox-card border: false entity: number.esp_inverter_prog1_capacity icon: none initial: 5 min: 16 max: 100 toggle_entity: switch.esp_inverter_prog1_grid_charge step: 2 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } - type: custom:numberbox-card border: false entity: number.esp_inverter_prog1_power icon: none initial: 5 min: 100 max: 5000 step: 100 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } layout_options: grid_columns: 8 grid_rows: auto visibility: - condition: state entity: binary_sensor.time_1 state: "on" - type: vertical-stack cards: - type: markdown content: " **{{ states('sensor.esp_inverter_time_slot_2') }} đến {{ states('sensor.esp_inverter_time_slot_3') }}**" card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: horizontal-stack cards: - type: custom:numberbox-card border: false entity: number.esp_inverter_prog2_capacity icon: none initial: 5 min: 16 max: 100 toggle_entity: switch.esp_inverter_prog2_grid_charge step: 2 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } - type: custom:numberbox-card border: false entity: number.esp_inverter_prog2_power icon: none initial: 5 min: 100 max: 5000 step: 100 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } layout_options: grid_columns: 8 grid_rows: auto visibility: - condition: state entity: binary_sensor.time_2 state: "on" - type: vertical-stack cards: - type: markdown content: " **{{ states('sensor.esp_inverter_time_slot_3') }} đến {{ states('sensor.esp_inverter_time_slot_4') }}**" card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: horizontal-stack cards: - type: custom:numberbox-card border: false entity: number.esp_inverter_prog3_capacity icon: none initial: 5 min: 16 max: 100 toggle_entity: switch.esp_inverter_prog3_grid_charge step: 2 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } - type: custom:numberbox-card border: false entity: number.esp_inverter_prog3_power icon: none initial: 5 min: 100 max: 5000 step: 100 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } layout_options: grid_columns: 8 grid_rows: auto visibility: - condition: state entity: binary_sensor.time_3 state: "on" - type: vertical-stack cards: - type: markdown content: " **{{ states('sensor.esp_inverter_time_slot_4') }} đến {{ states('sensor.esp_inverter_time_slot_5') }}**" card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: horizontal-stack cards: - type: custom:numberbox-card border: false entity: number.esp_inverter_prog4_capacity icon: none initial: 5 min: 16 max: 100 toggle_entity: switch.esp_inverter_prog4_grid_charge step: 2 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } - type: custom:numberbox-card border: false entity: number.esp_inverter_prog4_power icon: none initial: 5 min: 100 max: 5000 step: 100 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } layout_options: grid_columns: 8 grid_rows: auto visibility: - condition: state entity: binary_sensor.time_4 state: "on" - type: vertical-stack cards: - type: markdown content: " **{{ states('sensor.esp_inverter_time_slot_5') }} đến {{ states('sensor.esp_inverter_time_slot_6') }}**" card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: horizontal-stack cards: - type: custom:numberbox-card border: false entity: number.esp_inverter_prog5_capacity icon: none initial: 5 min: 16 max: 100 toggle_entity: switch.esp_inverter_prog5_grid_charge step: 2 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } - type: custom:numberbox-card border: false entity: number.esp_inverter_prog5_power icon: none initial: 5 min: 100 max: 5000 step: 100 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } layout_options: grid_columns: 8 grid_rows: auto visibility: - condition: state entity: binary_sensor.time_5 state: "on" - type: vertical-stack cards: - type: markdown content: " **{{ states('sensor.esp_inverter_time_slot_6') }} đến {{ states('sensor.esp_inverter_time_slot_1') }}**" card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: horizontal-stack cards: - type: custom:numberbox-card border: false entity: number.esp_inverter_prog6_capacity icon: none initial: 5 min: 16 max: 100 toggle_entity: switch.esp_inverter_prog6_grid_charge step: 2 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } - type: custom:numberbox-card border: false entity: number.esp_inverter_prog6_power icon: none initial: 5 min: 100 max: 5000 step: 100 icon_plus: mdi:plus-circle icon_minus: mdi:minus-circle name: false unit: false speed: 200 card_mod: style: | ha-card { height: 52px; display: flex; flex-direction: column; justify-content: center; } layout_options: grid_columns: 8 grid_rows: auto visibility: - condition: state entity: binary_sensor.time_6 state: "on" grid_options: columns: 24 rows: 2 - type: grid cards: - type: custom:myjdownloader-card display_mode: compact list_mode: packages hide_instance: true hide_title: false hide_play: false hide_pause: false hide_stop: false hide_speed_limit: false visibility: - condition: numeric_state entity: sensor.jdownloader_plex_download_speed above: 1 max_columns: 4 dense_section_placement: true
-
Tạo giao diện giám sát Pin trên Home Assistant
Các addon cài trong hass yêu cầu cần có
* Bubble Card
* Bar cardCode để card
type: grid cards: - type: heading heading: Pack 130Ah heading_style: title - type: custom:bubble-card card_type: button sub_button: - entity: switch.jk_130_charging name: Sạc show_name: false show_background: true show_state: true show_last_changed: false show_attribute: false icon: mdi:battery-charging-high tap_action: action: toggle double_tap_action: action: toggle hold_action: action: toggle - entity: switch.jk_130_discharging name: Xả show_state: true show_name: false show_last_changed: false icon: mdi:battery-minus-outline tap_action: action: toggle - entity: switch.jk_130_balancer show_name: true name: Cân Bằng tap_action: action: toggle entity: switch.jk_130_enable_bluetooth_connection show_name: false show_last_changed: false show_attribute: false show_state: true card_layout: large styles: "" tap_action: action: none - type: vertical-stack cards: - type: custom:stack-in-card keep: margin: false box_shadow: false background: false cards: - type: grid square: false columns: 2 cards: - type: markdown content: >- <center><b><font color=#bda442 size=6>{{ states('sensor.jk_130_total_voltage') }} V</font></b><br> C.Suất: <font color=#bda442>{{ states('sensor.jk_130_power') }} W</font><br> D.Lượng: <font color=#bda442>{{ states('sensor.jk_130_total_battery_capacity_setting') }} Ah</font><br> Xả: <font color=#bda442>{{ states('sensor.jk_130_total_charging_cycle_capacity') }} Ah</font><br> Áp TB.: <font color=#bda442>{{ states('sensor.jk_130_average_cell_voltage') }} V</font><br> Cân bằng: <font color=#bda442>{{ states('sensor.jk_130_balancing_current') }} A</font><br> - type: markdown content: >- <center><b><font color=#bda442 size=6>{{ states('sensor.jk_130_current') }} A</font></b><br> SOC: <font color=#bda442>{{ states('sensor.jk_130_state_of_charge') }} %</font><br> Còn: <font color=#bda442>{{ states('sensor.jk_130_capacity_remaining') }} Ah</font><br> Chu kỳ: <font color=#bda442>{{ states('sensor.jk_130_charging_cycles') }}</font><br> Lệch Cell.: <font color=#bda442>{{ states('sensor.jk_130_delta_cell_voltage') }} V</font><br> Nhiệt MOS.: <font color=#bda442>{{ states('sensor.jk_130_power_tube_temperature') }} °C</font><br> Nhiệt T1: <font color=#bda442>{{ states('sensor.jk_130_temperature_sensor_1') }} °C</font><br> Nhiệt T2: <font color=#bda442>{{ states('sensor.jk_130_temperature_sensor_2') }} °C</font><br> card_mod: style: | ha-card { backdrop-filter: blur(10px); box-shadow: none; border: none } - type: horizontal-stack cards: - type: custom:bar-card direction: up columns: 8 decimal: 3 max: 3.45 min: 3 height: 80px severity: - color: darkred from: 3.45 to: 4 - color: darkorange from: 3.4 to: 3.45 - color: rgb(189, 164, 66) from: 3.1 to: 3.4 - color: darkred from: 2.5 to: 3.1 positions: icon: "off" indicator: inside name: inside entities: - entity: sensor.jk_130_cell_voltage_1 name: Cell 01 - entity: sensor.jk_130_cell_voltage_2 name: Cell 02 - entity: sensor.jk_130_cell_voltage_3 name: Cell 03 - entity: sensor.jk_130_cell_voltage_4 name: Cell 04 - entity: sensor.jk_130_cell_voltage_5 name: Cell 05 - entity: sensor.jk_130_cell_voltage_6 name: Cell 06 - entity: sensor.jk_130_cell_voltage_7 name: Cell 07 - entity: sensor.jk_130_cell_voltage_8 name: Cell 08 - entity: sensor.jk_130_cell_voltage_9 name: Cell 09 - entity: sensor.jk_130_cell_voltage_10 name: Cell 10 - entity: sensor.jk_130_cell_voltage_11 name: Cell 11 - entity: sensor.jk_130_cell_voltage_12 name: Cell 12 - entity: sensor.jk_130_cell_voltage_13 name: Cell 13 - entity: sensor.jk_130_cell_voltage_14 name: Cell 14 - entity: sensor.jk_130_cell_voltage_15 name: Cell 15 card_mod: style: |- bar-card-value { margin-right: auto; margin-left: auto; margin-bottom: 15px; font-size: 10px; font-weight: normal; } bar-card-name { margin-right: auto; margin-left: auto; margin-bottom: 0px; font-size: 7px; font-weight: normal; } - type: custom:stack-in-card keep: margin: false box_shadow: false background: false cards: - type: grid square: false columns: 2 cards: - type: markdown content: >- <center>01. {% if states('sensor.jk_130_max_voltage_cell') == '1' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_1') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '1' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_1') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_1') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_1') }} Ω <br> 02. {% if states('sensor.jk_130_max_voltage_cell') == '2' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_2') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '2' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_2') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_2') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_2') }} Ω <br> 03. {% if states('sensor.jk_130_max_voltage_cell') == '3' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_3') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '3' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_3') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_3') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_3') }} Ω <br> 04. {% if states('sensor.jk_130_max_voltage_cell') == '4' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_4') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '4' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_4') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_4') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_4') }} Ω <br> 05. {% if states('sensor.jk_130_max_voltage_cell') == '5' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_5') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '5' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_5') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_5') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_5') }} Ω <br> 06. {% if states('sensor.jk_130_max_voltage_cell') == '6' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_6') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '6' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_6') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_6') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_6') }} Ω <br> 07. {% if states('sensor.jk_130_max_voltage_cell') == '7' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_7') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '7' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_7') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_7') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_7') }} Ω <br> 08. {% if states('sensor.jk_130_max_voltage_cell') == '8' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_8') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '8' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_8') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_8') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_8') }} Ω <br></center> - type: markdown content: >- <center>09. {% if states('sensor.jk_130_max_voltage_cell') == '9' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_9') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '9' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_9') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_9') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_9') }} Ω <br> 10. {% if states('sensor.jk_130_max_voltage_cell') == '10' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_10') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '10' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_10') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_10') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_10') }} Ω <br> 11. {% if states('sensor.jk_130_max_voltage_cell') == '11' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_11') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '11' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_11') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_11') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_11') }} Ω <br> 12. {% if states('sensor.jk_130_max_voltage_cell') == '12' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_12') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '12' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_12') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_12') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_12') }} Ω <br> 13. {% if states('sensor.jk_130_max_voltage_cell') == '13' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_13') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '13' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_13') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_13') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_13') }} Ω <br> 14. {% if states('sensor.jk_130_max_voltage_cell') == '14' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_14') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '14' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_14') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_14') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_14') }} Ω <br> 15. {% if states('sensor.jk_130_max_voltage_cell') == '15' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_15') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '15' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_15') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_15') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_15') }} Ω <br> 16. {% if states('sensor.jk_130_max_voltage_cell') == '16' %} <font color="#3090C7">{{ states('sensor.jk_130_cell_voltage_16') }} V</font> {% elif states('sensor.jk_130_min_voltage_cell') == '16' %} <font color="red">{{ states('sensor.jk_130_cell_voltage_16') }} V</font> {% else %} {{ states('sensor.jk_130_cell_voltage_16') }} V {% endif %} / {{ states('sensor.jk_130_cell_resistance_16') }} Ω <br></center>
-
Tạo biến template tính giá điện bậc thang EVN
Để tính tiền điện theo bậc thang trong home assistant bạn có thể tạo một biến trợ giúp dạng template và điền đoạn code này vào.
Tạo biến trợ giúp ở đây: http://homeassistant/:8123/config/helpers
Hãy đặt tên biến trợ giúp và dán đoạn code bên dưới vào khung “Bản mẫu trạng thái”, thay thế sensor chứa chỉ số điện của bạn thì biến sẽ trả về số tiền điện tính theo bậc thang của EVN
[adsga]
{% set number = states('sensor.chi_so_kwh_dien cua ban') | int %} {% set total = 0 %} {% if number > 400 %} {% set total = total + (number - 400) * 3302 %} {% set number = 400 %} {% endif %} {% if number > 300 %} {% set total = total + (number - 300) * 3197 %} {% set number = 300 %} {% endif %} {% if number > 200 %} {% set total = total + (number - 200) * 2806 %} {% set number = 200 %} {% endif %} {% if number > 100 %} {% set total = total + (number - 100) * 2271 %} {% set number = 100 %} {% endif %} {% if number > 50 %} {% set total = total + (number - 50) * 1956 %} {% set number = 50 %} {% endif %} {% set total = total + number * 1893 %} {{ total + (total * 0.08) | float | round(0) }}
-
Mạch ESP32 kết nối BLE giám sát BMS JK
Hướng dẫn làm mạch ESP32 kết nối BLE theo dõi BMS JK
Code nạp ESP32:
Yêu cầu:
– Xác định được MAC Address của BLE khối pin để sửa code
– Xác định được phân loại mạchsubstitutions: name: jk-bms device_description: "Giam sat BMS JK qua BLE -bachtrannet" external_components_source: github://syssi/esphome-jk-bms@main mac_address: C8:47:80:0D:0A:DA #thay thế bằng MAC Address của thiết bị bạn đang dùng # Please use "JK02_24S" if you own a old JK-BMS < hardware version 11.0 (hardware version >= 6.0 and < 11.0) # Please use "JK02_32S" if you own a new JK-BMS >= hardware version 11.0 (f.e. JK-B2A8S20P hw 11.XW, sw 11.26) # Please use "JK04" if you have some old JK-BMS <= hardware version 3.0 (f.e. JK-B2A16S hw 3.0, sw. 3.3.0) protocol_version: JK02_32S #Xem thông số mạch BMS so sánh với dòng trên sau đó điền vào dữ liệu phù hợp esphome: name: bms-jk comment: ${device_description} min_version: 2024.6.0 project: name: "syssi.esphome-jk-bms" version: 2.1.0 esp32: board: wemos_d1_mini32 framework: type: esp-idf external_components: - source: ${external_components_source} refresh: 0s wifi: ssid: !secret wifi_ssid password: !secret wifi_password ota: platform: esphome password: "c717640ea7d277aa25558a86f2e6bf57" on_begin: then: - switch.turn_off: ble_client_switch0 - logger.log: "BLE connection suspended for OTA update" logger: level: DEBUG logs: esp32_ble_tracker: INFO esp32_ble_client: INFO # If you don't use Home Assistant please remove this `api` section and uncomment the `mqtt` component! api: encryption: key: "lFC5laOAwjcbihrZmiOTlTGZp2s5kyqwSZ/g5Tl5lhg=" # mqtt: # broker: !secret mqtt_host # username: !secret mqtt_username # password: !secret mqtt_password # id: mqtt_client esp32_ble_tracker: scan_parameters: active: false on_ble_advertise: then: - lambda: |- if (x.get_name().rfind("JK-", 0) == 0 || x.get_name().rfind("JK_", 0) == 0) { ESP_LOGI("ble_adv", "Tim thay JK-BMS moi"); ESP_LOGI("ble_adv", " Name: %s", x.get_name().c_str()); ESP_LOGI("ble_adv", " MAC address: %s", x.address_str().c_str()); ESP_LOGD("ble_adv", " Advertised service UUIDs:"); for (auto uuid : x.get_service_uuids()) { ESP_LOGD("ble_adv", " - %s", uuid.to_string().c_str()); } } ble_client: - mac_address: ${mac_address} id: client0 jk_bms_ble: - ble_client_id: client0 protocol_version: ${protocol_version} throttle: 1s id: bms0 binary_sensor: - platform: jk_bms_ble balancing: name: "${name} balancing" charging: name: "${name} charging" discharging: name: "${name} discharging" heating: name: "${name} heating" online_status: name: "${name} online status" button: - platform: jk_bms_ble retrieve_settings: name: "${name} retrieve settings" retrieve_device_info: name: "${name} retrieve device info" number: - platform: jk_bms_ble jk_bms_ble_id: bms0 balance_trigger_voltage: name: "${name} balance trigger voltage" cell_count: name: "${name} cell count" total_battery_capacity: name: "${name} total battery capacity" cell_voltage_overvoltage_protection: name: "${name} cell voltage overvoltage protection" cell_voltage_overvoltage_recovery: name: "${name} cell voltage overvoltage recovery" cell_voltage_undervoltage_protection: name: "${name} cell voltage undervoltage protection" cell_voltage_undervoltage_recovery: name: "${name} cell voltage undervoltage recovery" balance_starting_voltage: name: "${name} balance starting voltage" voltage_calibration: name: "${name} voltage calibration" current_calibration: name: "${name} current calibration" power_off_voltage: name: "${name} power off voltage" max_balance_current: name: "${name} max balance current" max_charge_current: name: "${name} max charge current" max_discharge_current: name: "${name} max discharge current" charge_overcurrent_protection_delay: name: "${name} charge overcurrent protection delay" charge_overcurrent_protection_recovery_time: name: "${name} charge overcurrent protection recovery time" discharge_overcurrent_protection_delay: name: "${name} discharge overcurrent protection delay" discharge_overcurrent_protection_recovery_time: name: "${name} discharge overcurrent protection recovery time" short_circuit_protection_delay: name: "${name} short circuit protection delay" short_circuit_protection_recovery_time: name: "${name} short circuit protection recovery time" charge_overtemperature_protection: name: "${name} charge overtemperature protection" charge_overtemperature_protection_recovery: name: "${name} charge overtemperature protection recovery" discharge_overtemperature_protection: name: "${name} discharge overtemperature protection" discharge_overtemperature_protection_recovery: name: "${name} discharge overtemperature protection recovery" charge_undertemperature_protection: name: "${name} charge undertemperature protection" charge_undertemperature_protection_recovery: name: "${name} charge undertemperature protection recovery" power_tube_overtemperature_protection: name: "${name} power tube overtemperature protection" power_tube_overtemperature_protection_recovery: name: "${name} power tube overtemperature protection recovery" sensor: - platform: jk_bms_ble jk_bms_ble_id: bms0 min_cell_voltage: name: "${name} min cell voltage" max_cell_voltage: name: "${name} max cell voltage" min_voltage_cell: name: "${name} min voltage cell" max_voltage_cell: name: "${name} max voltage cell" delta_cell_voltage: name: "${name} delta cell voltage" average_cell_voltage: name: "${name} average cell voltage" cell_voltage_1: name: "${name} cell voltage 1" cell_voltage_2: name: "${name} cell voltage 2" cell_voltage_3: name: "${name} cell voltage 3" cell_voltage_4: name: "${name} cell voltage 4" cell_voltage_5: name: "${name} cell voltage 5" cell_voltage_6: name: "${name} cell voltage 6" cell_voltage_7: name: "${name} cell voltage 7" cell_voltage_8: name: "${name} cell voltage 8" cell_voltage_9: name: "${name} cell voltage 9" cell_voltage_10: name: "${name} cell voltage 10" cell_voltage_11: name: "${name} cell voltage 11" cell_voltage_12: name: "${name} cell voltage 12" cell_voltage_13: name: "${name} cell voltage 13" cell_voltage_14: name: "${name} cell voltage 14" cell_voltage_15: name: "${name} cell voltage 15" cell_voltage_16: name: "${name} cell voltage 16" cell_voltage_17: name: "${name} cell voltage 17" cell_voltage_18: name: "${name} cell voltage 18" cell_voltage_19: name: "${name} cell voltage 19" cell_voltage_20: name: "${name} cell voltage 20" cell_voltage_21: name: "${name} cell voltage 21" cell_voltage_22: name: "${name} cell voltage 22" cell_voltage_23: name: "${name} cell voltage 23" cell_voltage_24: name: "${name} cell voltage 24" cell_resistance_1: name: "${name} cell resistance 1" cell_resistance_2: name: "${name} cell resistance 2" cell_resistance_3: name: "${name} cell resistance 3" cell_resistance_4: name: "${name} cell resistance 4" cell_resistance_5: name: "${name} cell resistance 5" cell_resistance_6: name: "${name} cell resistance 6" cell_resistance_7: name: "${name} cell resistance 7" cell_resistance_8: name: "${name} cell resistance 8" cell_resistance_9: name: "${name} cell resistance 9" cell_resistance_10: name: "${name} cell resistance 10" cell_resistance_11: name: "${name} cell resistance 11" cell_resistance_12: name: "${name} cell resistance 12" cell_resistance_13: name: "${name} cell resistance 13" cell_resistance_14: name: "${name} cell resistance 14" cell_resistance_15: name: "${name} cell resistance 15" cell_resistance_16: name: "${name} cell resistance 16" cell_resistance_17: name: "${name} cell resistance 17" cell_resistance_18: name: "${name} cell resistance 18" cell_resistance_19: name: "${name} cell resistance 19" cell_resistance_20: name: "${name} cell resistance 20" cell_resistance_21: name: "${name} cell resistance 21" cell_resistance_22: name: "${name} cell resistance 22" cell_resistance_23: name: "${name} cell resistance 23" cell_resistance_24: name: "${name} cell resistance 24" total_voltage: name: "${name} total voltage" current: name: "${name} current" heating_current: name: "${name} heating current" power: name: "${name} power" charging_power: name: "${name} charging power" discharging_power: name: "${name} discharging power" temperature_sensor_1: name: "${name} temperature sensor 1" temperature_sensor_2: name: "${name} temperature sensor 2" temperature_sensor_3: name: "${name} temperature sensor 3" temperature_sensor_4: name: "${name} temperature sensor 4" power_tube_temperature: name: "${name} power tube temperature" balancing: name: "${name} balancing" state_of_charge: name: "${name} state of charge" capacity_remaining: name: "${name} capacity remaining" total_battery_capacity_setting: name: "${name} total battery capacity setting" charging_cycles: name: "${name} charging cycles" total_charging_cycle_capacity: name: "${name} total charging cycle capacity" total_runtime: name: "${name} total runtime" balancing_current: name: "${name} balancing current" errors_bitmask: name: "${name} errors bitmask" switch: - platform: jk_bms_ble charging: name: "${name} charging" discharging: name: "${name} discharging" balancer: name: "${name} balancer" - platform: ble_client ble_client_id: client0 id: ble_client_switch0 name: "${name} enable bluetooth connection" text_sensor: - platform: jk_bms_ble errors: name: "${name} errors" total_runtime_formatted: name: "${name} total runtime formatted"
Demo giao diện mình đang dùng trên Dashboard
Code YAML Dashboad
cards: - type: vertical-stack cards: - type: horizontal-stack cards: - type: horizontal-stack cards: - type: custom:bubble-card card_type: button entity: switch.jk_bms_charging name: Sạc show_state: false force_icon: false show_attribute: false show_last_changed: false sub_button: - entity: switch.jk_bms_charging show_name: false name: Đang sạc show_state: true show_attribute: false show_last_changed: false styles: "" button_type: state icon: mdi:battery-positive - type: horizontal-stack cards: - type: custom:bubble-card card_type: button entity: switch.jk_bms_discharging name: Xả show_state: false force_icon: false show_attribute: false show_last_changed: false sub_button: - entity: switch.jk_bms_charging show_name: false name: Đang xả show_state: true show_attribute: false show_last_changed: false button_type: state icon: mdi:battery-negative - type: horizontal-stack cards: - type: custom:bubble-card card_type: button entity: switch.jk_bms_balancer name: Cân bằng show_state: false force_icon: false show_attribute: false show_last_changed: false sub_button: - entity: switch.jk_bms_charging show_name: false name: Đang sạc show_state: true show_attribute: false show_last_changed: false button_type: state - type: custom:stack-in-card keep: margin: false box_shadow: false background: false cards: - type: grid square: false columns: 1 cards: - type: markdown content: >- <center><b><font color=#41CD52 size=6>{{ states('sensor.jk_bms_total_voltage') }} V</font></b><br> Công Suất: <font color=#41CD52>{{ states('sensor.jk_bms_power') }} W</font><br> Dung Lượng: <font color=#41CD52>{{ states('sensor.jk_bms_total_battery_capacity_setting') }} Ah</font><br> Tổng Cycle: <font color=#41CD52>{{ states('sensor.jk_bms_total_charging_cycle_capacity') }} Ah</font><br> Áp Trung Bình.: <font color=#41CD52>{{ states('sensor.jk_bms_average_cell_voltage') }} V</font><br> Dòng cân bằng: <font color=#41CD52>{{ states('sensor.jk_bms_balancing_current') }} A</font><br> Nhiệt T1: <font color=#41CD52>{{ states('sensor.jk_bms_temperature_sensor_1') }} °C</font> - type: markdown content: >- <center><b><font color=#41CD52 size=6>{{ states('sensor.jk_bms_current') }} A</font></b><br> SOC: <font color=#41CD52>{{ states('sensor.jk_bms_state_of_charge') }} %</font><br> Còn: <font color=#41CD52>{{ states('sensor.jk_bms_capacity_remaining') }} Ah</font><br> Chu kỳ: <font color=#41CD52>{{ states('sensor.jk_bms_charging_cycles') }}</font><br> Lệch Cell.: <font color=#41CD52>{{ states('sensor.jk_bms_delta_cell_voltage') }} V</font><br> Nhiệt MOS.: <font color=#41CD52>{{ states('sensor.jk_bms_power_tube_temperature') }} °C</font><br> Nhiệt T2: <font color=#41CD52>{{ states('sensor.jk_bms_temperature_sensor_2') }} °C</font> - type: custom:stack-in-card keep: margin: false box_shadow: false background: false cards: - type: grid square: false columns: 1 cards: - type: markdown content: <center><b>Cells - type: grid square: false columns: 2 cards: - type: markdown content: >- <center>01. {% if states('sensor.jk_bms_max_voltage_cell') == '1' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_1') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '1' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_1') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_1') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_1') }} Ω <br> 02. {% if states('sensor.jk_bms_max_voltage_cell') == '2' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_2') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '2' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_2') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_2') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_2') }} Ω <br> 03. {% if states('sensor.jk_bms_max_voltage_cell') == '3' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_3') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '3' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_3') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_3') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_3') }} Ω <br> 04. {% if states('sensor.jk_bms_max_voltage_cell') == '4' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_4') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '4' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_4') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_4') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_4') }} Ω <br> 05. {% if states('sensor.jk_bms_max_voltage_cell') == '5' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_5') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '5' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_5') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_5') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_5') }} Ω <br> 06. {% if states('sensor.jk_bms_max_voltage_cell') == '6' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_6') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '6' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_6') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_6') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_6') }} Ω <br> 07. {% if states('sensor.jk_bms_max_voltage_cell') == '7' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_7') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '7' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_7') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_7') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_7') }} Ω <br> 08. {% if states('sensor.jk_bms_max_voltage_cell') == '8' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_8') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '8' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_8') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_8') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_8') }} Ω <br></center> - type: markdown content: >- <center>09. {% if states('sensor.jk_bms_max_voltage_cell') == '9' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_9') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '9' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_9') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_9') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_9') }} Ω <br> 10. {% if states('sensor.jk_bms_max_voltage_cell') == '10' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_10') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '10' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_10') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_10') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_10') }} Ω <br> 11. {% if states('sensor.jk_bms_max_voltage_cell') == '11' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_11') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '11' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_11') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_11') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_11') }} Ω <br> 12. {% if states('sensor.jk_bms_max_voltage_cell') == '12' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_12') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '12' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_12') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_12') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_12') }} Ω <br> 13. {% if states('sensor.jk_bms_max_voltage_cell') == '13' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_13') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '13' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_13') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_13') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_13') }} Ω <br> 14. {% if states('sensor.jk_bms_max_voltage_cell') == '14' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_14') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '14' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_14') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_14') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_14') }} Ω <br> 15. {% if states('sensor.jk_bms_max_voltage_cell') == '15' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_15') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '15' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_15') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_15') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_15') }} Ω <br> 16. {% if states('sensor.jk_bms_max_voltage_cell') == '16' %} <font color="#3090C7">{{ states('sensor.jk_bms_cell_voltage_16') }} V</font> {% elif states('sensor.jk_bms_min_voltage_cell') == '16' %} <font color="red">{{ states('sensor.jk_bms_cell_voltage_16') }} V</font> {% else %} {{ states('sensor.jk_bms_cell_voltage_16') }} V {% endif %} / {{ states('sensor.jk_bms_cell_resistance_16') }} Ω <br></center> - type: horizontal-stack cards: - type: custom:battery-state-card icon: mdi:battery colors: steps: - value: 3.2 color: red - value: 3.25 color: yellow - value: 3.3 color: blue - value: 3.4 color: green tap_action: action: more-info collapse: 8 sort: by: state desc: true unit: V entities: - entity: sensor.jk_bms_cell_voltage_1 decimals: 3 name: Cell 1 - entity: sensor.jk_bms_cell_voltage_2 decimals: 3 name: Cell 2 - entity: sensor.jk_bms_cell_voltage_3 decimals: 3 name: Cell 3 - entity: sensor.jk_bms_cell_voltage_4 decimals: 3 name: Cell 4 - entity: sensor.jk_bms_cell_voltage_5 decimals: 3 name: Cell 5 - entity: sensor.jk_bms_cell_voltage_6 decimals: 3 name: Cell 6 - entity: sensor.jk_bms_cell_voltage_7 decimals: 3 name: Cell 7 - entity: sensor.jk_bms_cell_voltage_8 decimals: 3 name: Cell 8 - type: custom:battery-state-card icon: mdi:battery colors: steps: - value: 3.2 color: red - value: 3.25 color: yellow - value: 3.3 color: blue - value: 3.4 color: green tap_action: action: more-info collapse: 8 sort: by: state desc: true unit: V entities: - entity: sensor.jk_bms_cell_voltage_9 decimals: 3 name: Cell 9 - entity: sensor.jk_bms_cell_voltage_10 decimals: 3 name: Cell 10 - entity: sensor.jk_bms_cell_voltage_11 decimals: 3 name: Cell 11 - entity: sensor.jk_bms_cell_voltage_12 decimals: 3 name: Cell 12 - entity: sensor.jk_bms_cell_voltage_13 decimals: 3 name: Cell 13 - entity: sensor.jk_bms_cell_voltage_14 decimals: 3 name: Cell 14 - entity: sensor.jk_bms_cell_voltage_15 decimals: 3 name: Cell 15 - entity: sensor.jk_bms_cell_voltage_16 decimals: 3 name: Cell 16 title: JK BMS theme: ios-dark-mode-dark-green type: custom:vertical-layout
Nếu anh em muốn giao diện giống JK thì tự tìm trên mạng có nhé
-
Vòng thể hiện điện năng cho Home Assistant
type: horizontal-stack cards: - type: custom:flex-horseshoe-card view_layout: grid-area: g2 entities: - entity: sensor.tong_pv decimals: 0 unit: W name: PV - entity: sensor.esp_inverter_battery_soc decimals: 0 - entity: sensor.jk_bms_state_of_charge decimals: 0 - entity: sensor.abs_battery decimals: 0 name: CS PIN - entity: sensor.esp_inverter_day_pv_energy_local decimals: 2 unit: kWh name: SẢN LƯỢNG - entity: sensor.esp_inverter_day_battery_charge decimals: 2 unit: kWh name: SẠC PIN - entity: sensor.abs_ufo decimals: 2 - entity: sensor.abs_dong_jk decimals: 2 - entity: input_text.trang_thai_pin decimals: 0 show: horseshoe_style: lineargradient layout: hlines: - id: 0 xpos: 50 ypos: 40 length: 70 styles: - opacity: 0.2; states: - id: 0 entity_index: 0 xpos: 50 ypos: 33 styles: - font-size: 3em; - opacity: 0.9; - id: 1 entity_index: 1 xpos: 44 ypos: 50 styles: - font-size: 1.5em; - text-anchor: end; - id: 2 entity_index: 2 xpos: 58 ypos: 50 styles: - text-anchor: start; - font-size: 1.5em; - id: 3 entity_index: 3 xpos: 50 ypos: 75 styles: - text-anchor: middle; - font-size: 2em; - id: 4 entity_index: 4 xpos: 76 ypos: 7 styles: - text-anchor: start; - font-size: 1.2em; - id: 5 entity_index: 5 xpos: 0 ypos: 7 styles: - text-anchor: start; - font-size: 1.2em; - id: 6 entity_index: 6 xpos: 36 ypos: 60 styles: - font-size: 1.2em; - id: 7 entity_index: 7 xpos: 58 ypos: 60 styles: - text-anchor: start; - font-size: 1.2em; - id: 8 entity_index: 8 xpos: 50 ypos: 55 styles: - font-size: 2em; icons: - id: 0 entity_index: 1 xpos: 30 ypos: 52 align: start size: 1 names: - id: 0 entity_index: 0 xpos: 50 ypos: 95 styles: - font-size: 1.2em; - id: 1 entity_index: 4 xpos: 81 ypos: 12 styles: - font-size: 0.5em; - text-anchor: start; - id: 2 entity_index: 5 xpos: 0 ypos: 12 styles: - font-size: 0.5em; - text-anchor: start; - id: 3 entity_index: 3 xpos: 50 ypos: 80 styles: - font-size: 0.65em; - text-anchor: middle; horseshoe_scale: min: 0 max: 6000 width: 6 color_stops: '10': green '5000': orange card_mod: style: | ha-card { --ha-card-background: var(--card-background-color); color: var(--primary-color); } - type: custom:flex-horseshoe-card view_layout: grid-area: g3 entities: - entity: sensor.esp_inverter_essential_power_1 unit: W name: ĐANG SỬ DỤNG - entity: sensor.esp_inverter_inverter_voltage decimals: 0 unit: V - entity: sensor.esp_inverter_grid_frequency decimals: 2 unit: Hz name: Công suất - entity: sensor.abs_grid_power decimals: 0 unit: W name: CS Lưới - entity: sensor.esp_inverter_day_grid_import decimals: 2 unit: kWh name: Mua về - entity: sensor.esp_inverter_day_load_energy decimals: 2 unit: kWh name: Tự dùng - entity: input_text.trang_thai_luoi decimals: 0 show: horseshoe_style: autominmax layout: hlines: - id: 0 xpos: 50 ypos: 40 length: 70 styles: - opacity: 0.2; - id: 0 xpos: 50 ypos: 60 length: 70 styles: - opacity: 0.2; vlines: - id: 0 xpos: 50 ypos: 50 length: 18 styles: - opacity: 0.2; states: - id: 0 entity_index: 0 xpos: 50 ypos: 33 styles: - font-size: 3em; - opacity: 0.9; - text-anchor: middle; - id: 1 entity_index: 1 xpos: 44 ypos: 53 styles: - font-size: 1.5em; - text-anchor: end; - id: 2 entity_index: 2 xpos: 55 ypos: 53 styles: - text-anchor: start; - font-size: 1.5em; - id: 3 entity_index: 3 xpos: 50 ypos: 75 styles: - text-anchor: middle; - font-size: 2em; - id: 4 entity_index: 4 xpos: 75 ypos: 7 styles: - text-anchor: start; - font-size: 1.2em; - id: 5 entity_index: 5 xpos: 0 ypos: 7 styles: - text-anchor: start; - font-size: 1.2em; - id: 6 entity_index: 6 xpos: 50 ypos: 61 styles: - font-size: 2em; icons: - id: 0 entity_index: 1 xpos: 30 ypos: 52 align: start size: 1 names: - id: 0 entity_index: 0 xpos: 50 ypos: 95 styles: - font-size: 1.2em; - id: 1 entity_index: 4 xpos: 85 ypos: 12 styles: - font-size: 0.65em; - text-anchor: start; - id: 2 entity_index: 5 xpos: 0 ypos: 12 styles: - font-size: 0.65em; - text-anchor: start; - id: 3 entity_index: 3 xpos: 50 ypos: 80 styles: - font-size: 0.65em; - text-anchor: middle; horseshoe_scale: min: 0 max: 6000 width: 6 color_stops: '0': orange '2000': orange visibility: - condition: numeric_state entity: sensor.tong_pv above: 100
Note: tạo thêm các biến trợ giúp trong home assistant để hỗ trợ hiển thị những thông tin chưa có sẵn biến
-
Các chart phân tích năng lượng điện mặt trời
type: custom:apexcharts-card chart_type: donut header: show: true show_states: true colorize_states: true title: Phân tích series: - entity: sensor.tu_su_dung name: Tự sử dụng type: column - entity: sensor.esp_inverter_day_battery_discharge_energy_local name: Xả Pin type: column - entity: sensor.esp_inverter_day_grid_import_energy_local name: Mua về type: column
type: custom:apexcharts-card chart_type: donut header: show: true show_states: true colorize_states: true title: Phân tích series: - entity: sensor.tu_su_dung name: Tự sử dụng type: column - entity: sensor.esp_inverter_day_battery_charge_energy_local name: Sạc Pin type: column
-
Dùng SOC hay Điện áp để đo dung lượng còn lại của pin?
SOC (State of Charge) và điện áp (Voltage) là hai phương pháp phổ biến để đo dung lượng còn lại của pin LiPo (Lithium Polymer). Mỗi phương pháp có ưu và nhược điểm riêng, và việc lựa chọn phương pháp nào phụ thuộc vào nhu cầu cụ thể của bạn. Dưới đây là sự khác biệt chi tiết giữa hai phương pháp này:
SOC (State of Charge)
SOC là một thuật ngữ dùng để chỉ trạng thái sạc của pin, được biểu thị dưới dạng phần trăm từ 0% đến 100%. SOC phản ánh mức độ năng lượng còn lại trong pin so với dung lượng tối đa của nó.
Ưu điểm của SOC:
- Độ chính xác cao: Khi được hiệu chỉnh và sử dụng đúng cách, SOC có thể cung cấp thông tin chính xác về dung lượng còn lại của pin.
- Không bị ảnh hưởng bởi tải: Đo SOC thường không bị ảnh hưởng bởi biến động dòng tải, do đó cho kết quả ổn định hơn so với đo điện áp.
- Phản ánh trạng thái thực tế: SOC phản ánh dung lượng thực tế còn lại của pin, thay vì chỉ đơn giản là một chỉ số tạm thời như điện áp.
[adsga]
Nhược điểm của SOC:
- Phức tạp: Để tính toán chính xác SOC, thường cần sử dụng mạch đo đặc biệt hoặc phần mềm phân tích, điều này có thể làm tăng chi phí và độ phức tạp.
- Hiệu chuẩn: Cần hiệu chuẩn thường xuyên để duy trì độ chính xác.
Điện áp (Voltage)
Đo điện áp là phương pháp đơn giản nhất để ước lượng dung lượng còn lại của pin. Điện áp của pin giảm dần khi pin xả.
Ưu điểm của đo điện áp:
- Đơn giản và dễ thực hiện: Đo điện áp có thể được thực hiện một cách dễ dàng với một voltmeter cơ bản.
- Chi phí thấp: Không cần thiết bị đo lường phức tạp hoặc phần mềm phức tạp.
[adsga]
Nhược điểm của đo điện áp:
- Độ chính xác thấp: Điện áp không phản ánh chính xác dung lượng còn lại của pin do nó phụ thuộc vào tải hiện tại, nhiệt độ, và nhiều yếu tố khác.
- Ảnh hưởng bởi tải: Khi tải thay đổi, điện áp có thể dao động lớn, dẫn đến ước tính sai về dung lượng còn lại.
- Không tuyến tính: Mối quan hệ giữa điện áp và dung lượng không hoàn toàn tuyến tính, nhất là đối với pin LiPo.
Nên Dùng SOC Hay Điện Áp?
- Dùng SOC: Nếu bạn cần độ chính xác cao và có khả năng sử dụng các thiết bị đo lường chuyên dụng, SOC là lựa chọn tốt hơn. SOC thích hợp cho các ứng dụng đòi hỏi biết chính xác mức năng lượng còn lại, chẳng hạn như trong xe điện hoặc các hệ thống lưu trữ năng lượng lớn.
- Dùng Điện Áp: Nếu bạn cần một giải pháp nhanh, đơn giản và chi phí thấp, hoặc chỉ cần ước lượng tạm thời dung lượng còn lại, đo điện áp có thể phù hợp hơn. Đây thường là lựa chọn cho các ứng dụng đơn giản như đồ chơi điều khiển từ xa hoặc các thiết bị điện tử nhỏ.
Biểu Đồ Quan Hệ Giữa Điện Áp Và SOC
Để có cái nhìn trực quan về mối quan hệ giữa điện áp và SOC, dưới đây là biểu đồ thể hiện tương quan này cho pin LiPo:
- Điện áp 4.2V: 100% SOC
- Điện áp 3.7V: 50% SOC
- Điện áp 3.2V: 0% SOC
Lưu ý rằng các giá trị này chỉ mang tính tham khảo và có thể thay đổi tùy theo đặc tính của từng loại pin cụ thể. Dưới đây là biểu đồ cụ thể:
[adsga]
plaintextSao chép mã
| SOC (%) | Điện Áp (V) | |---------|-------------| | 100 | 4.20 | | 90 | 4.10 | | 80 | 4.00 | | 70 | 3.90 | | 60 | 3.85 | | 50 | 3.80 | | 40 | 3.75 | | 30 | 3.70 | | 20 | 3.60 | | 10 | 3.50 | | 0 | 3.20 |
Kết Luận
Cả hai phương pháp đều có giá trị của chúng, và việc lựa chọn phương pháp nào phụ thuộc vào nhu cầu cụ thể và mức độ chính xác cần thiết. Nếu bạn có khả năng sử dụng các thiết bị đo SOC chuyên dụng, thì SOC sẽ cung cấp thông tin chính xác hơn về dung lượng pin còn lại. Ngược lại, nếu bạn cần một phương pháp đơn giản và nhanh chóng, đo điện áp là một lựa chọn hợp lý.
Tuy nhiên, để đạt được kết quả tối ưu, việc kết hợp cả hai phương pháp có thể mang lại cái nhìn toàn diện hơn về trạng thái của pin, giúp tối ưu hóa hiệu suất và tuổi thọ của pin LiPo trong các ứng dụng thực tế.
-
Tạo thông báo Telegram khi mất điện với Mikrotik
Giới thiệu
Bài viết này sẽ hướng dẫn bạn tạo một hệ thống thông báo trên Telegram khi mất điện lưới. Chúng ta sẽ sử dụng một thiết bị thông minh có kết nối internet với IP tĩnh và một script để kiểm tra kết nối với thiết bị đó. Khi mất kết nối (tức là thiết bị không trả lời ping), hệ thống sẽ gửi một thông báo đến Telegram.
Yêu cầu
- Thiết bị thông minh với IP tĩnh: Đảm bảo rằng thiết bị của bạn có thể kết nối internet và có một địa chỉ IP tĩnh.
- Router Mikrotik: Chúng ta sẽ sử dụng file .cmd để thực hiện ping và gửi thông báo.
- Tài khoản Telegram và một bot: Bạn cần tạo một bot Telegram và lấy API token của bot.
Bước 1: Tạo Bot Telegram
- Mở Telegram và tìm kiếm “@BotFather”.
- Bắt đầu trò chuyện với BotFather và gửi lệnh
/start
. - Gửi tiếp lệnh
/newbot
và làm theo hướng dẫn để tạo bot mới. - Sau khi tạo xong, bạn sẽ nhận được một API token. Hãy lưu lại token này để sử dụng sau.
[adsga]
Bước 2: Tạo Chat ID
- Tìm “@userinfobot” trên Telegram.
- Bắt đầu trò chuyện với bot này và gửi lệnh
/start
. - Bot sẽ trả về thông tin của bạn, bao gồm Chat ID. Hãy lưu lại Chat ID này.
Bước 3: Tạo một nhóm chat Thông báo
- Mở telegram tạo 1 nhóm chat bao gồm các thành viên muốn được nhận thông báo
- Add con bot bạn vừa tạo vào ở bước 1
- Lấy ID của nhóm chat bằng bot. ID nhóm chat có cấu trúc -xxxxxxxxxx
Bước 4: Cấu hình trên Mikrotik
Mục System -> Script bạn tạo lần lượt 2 Script như sau
Script 1: Ping kiểm tra thiết bị còn online không
Name: check-device
Source::local host "IP_TINH_THIET_BI" :local pingResult [/ping $host count=3] :if ($pingResult = 0) do={ /system script run send-telegram-message }
[adsga]
Script 2: Gửi tin nhắn telegram
Name: send-telegram-message
Source::local message "Thong bao mat ket noi toi thiet bị - MAT DIEN" /tool fetch url=("https://api.telegram.org/bot6419183476:AAHjc9sADvCMeHl1GbtOIzL-wGpEtvUyCPc/sendMessage?chat_id=-4263663211&text=" . $message) keep-result=no
Đoạn mã trên bạn thay thế API của con bot bạn vừa tạo vào và ID của nhóm chat telegram muốn nhận thông báo (Dòng chữ in đậm).
Tiếp theo bạn vào System -> Sechuduler để tạo lịch trình cho Script chạy.
Bạn tạo mới một lịch trình có tên: check-device
Start Time: startup
Interval: 00:01:00 <– giãn cách giữa các lần check
On event:/system script run check-device
Bước 5: Test thử.
Hãy tắt nguồn thiết bị có IP tĩnh đợi 1 phút xem quá trình gửi tin nhắn có thành công hay không nhé.
-
Tạo thông báo Telegram khi mất điện với Terminal
Giới thiệu
Bài viết này sẽ hướng dẫn bạn tạo một hệ thống thông báo trên Telegram khi mất điện lưới. Chúng ta sẽ sử dụng một thiết bị thông minh có kết nối internet với IP tĩnh và một script để kiểm tra kết nối với thiết bị đó. Khi mất kết nối (tức là thiết bị không trả lời ping), hệ thống sẽ gửi một thông báo đến Telegram.
Yêu cầu
- Thiết bị thông minh với IP tĩnh: Đảm bảo rằng thiết bị của bạn có thể kết nối internet và có một địa chỉ IP tĩnh.
- Máy tính chạy Windows: Chúng ta sẽ sử dụng file .cmd để thực hiện ping và gửi thông báo.
- Tài khoản Telegram và một bot: Bạn cần tạo một bot Telegram và lấy API token của bot.
Bước 1: Tạo Bot Telegram
- Mở Telegram và tìm kiếm “@BotFather”.
- Bắt đầu trò chuyện với BotFather và gửi lệnh
/start
. - Gửi tiếp lệnh
/newbot
và làm theo hướng dẫn để tạo bot mới. - Sau khi tạo xong, bạn sẽ nhận được một API token. Hãy lưu lại token này để sử dụng sau.
Bước 2: Tạo Chat ID
- Tìm “@userinfobot” trên Telegram.
- Bắt đầu trò chuyện với bot này và gửi lệnh
/start
. - Bot sẽ trả về thông tin của bạn, bao gồm Chat ID. Hãy lưu lại Chat ID này.
Bước 3: Viết Script Kiểm Tra Ping
- Mở Notepad và dán đoạn mã sau:
@echo off
setlocal
set DEVICE_IP=192.168.3.251
set TELEGRAM_API_KEY=6419181476:AAHjc9sADvCMeHl1GbtOIzL-wGpEtvUyCPc
set CHAT_ID=7017272641
set MESSAGE=Khong co ket noi toi %IP_ADDRESS%
:loop
ping -n 1 %DEVICE_IP% | find "TTL=" >nul
if errorlevel 1 (
curl -s -X POST https://api.telegram.org/bot6419181476:AAHjc9sADvCMeHl1GbtOIzL-wGpEtvUyCPc/sendMessage -d chat_id=7017272641 -d text="%MESSAGE%"
) else (
echo Ket noi thanh cong toi %IP_ADDRESS%
)
timeout /t 60 /nobreak
goto loop- Thay đổi các biến
DEVICE_IP
,TELEGRAM_API_KEY
, vàCHAT_ID
theo thông tin của bạn. - Lưu file với tên
check_power.cmd
.
Bước 4: Chạy Script
- Mở Command Prompt với quyền Admin.
- Điều hướng đến thư mục chứa file
check_power.cmd
. - Chạy file bằng lệnh:
check_power.cmd
Kết luận
Bây giờ, mỗi phút hệ thống sẽ ping thiết bị của bạn một lần. Nếu ping thất bại, nó sẽ gửi thông báo đến Telegram báo hiệu có thể mất điện lưới. Hệ thống sẽ tiếp tục chạy cho đến khi bạn tắt terminal.