substitutions: name: "karavan" friendly_name: "my smart karavan" esphome: name: "${name}" friendly_name: "${friendly_name}" name_add_mac_suffix: true esp32: board: esp32dev framework: type: arduino logger: #api: # password: "legna21" ota: password: "legna21" wifi: ssid: Mydor-office password: Av240971 ap: ssid: "Karavan Fallback Hotspot" password: "Karavan12345" reboot_timeout: 0s mqtt: broker: m6.wqtt.ru port: 12068 username: test8relay password: Test8Relay client_id: smartkaravan reboot_timeout: 0s web_server: port: 80 captive_portal: globals: - id: last_rf_code_on type: int restore_value: yes - id: last_rf_code_off type: int restore_value: yes - id: learn_mode_on type: bool initial_value: 'false' - id: learn_mode_off type: bool initial_value: 'false' - id: automation_shabbat_state type: bool initial_value: 'false' - id: on_executed type: bool initial_value: 'false' - id: off_executed type: bool initial_value: 'false' - id: selected_hour type: int restore_value: yes initial_value: '0' select: - platform: template name: "Hour Select" id: hour_select options: - "0" - "1" - "2" - "3" - "4" - "5" - "6" - "7" - "8" - "9" - "10" - "11" - "12" - "13" - "14" - "15" - "16" - "17" - "18" - "19" - "20" - "21" - "22" - "23" set_action: - lambda: |- id(selected_hour) = atoi(x.c_str()); time: - platform: sntp id: sntp_time servers: il.pool.ntp.org on_time: - seconds: /60 then: - lambda: |- if (id(sntp_time).now().hour == id(selected_hour)) { id(l1).turn_on(); } else { id(l1).turn_off(); } i2c: sda: GPIO4 scl: GPIO5 scan: true id: i2c_hub_in_1 remote_transmitter: pin: 2 carrier_duty_percent: 100% remote_receiver: pin: 15 dump: all filter: 250us tolerance: 50% idle: 4ms buffer_size: 2kb on_rc_switch: then: - if: condition: lambda: 'return id(learn_mode_on);' then: - globals.set: id: last_rf_code_on value: !lambda 'return x.code;' - if: condition: lambda: 'return id(learn_mode_off);' then: - globals.set: id: last_rf_code_off value: !lambda 'return x.code;' pcf8574: - id: 'pcf8574_hub_out_1' address: 0x24 - id: 'pcf8574_hub_in_1' address: 0x22 button: - platform: template name: "1) לימוד לחצן הדלקה " on_press: then: - lambda: |- id(learn_mode_on) = true; - delay: 5s - lambda: |- id(learn_mode_on) = false; - platform: template name: "2) לימוד לחצן כיבוי " on_press: then: - lambda: |- id(learn_mode_off) = true; - delay: 5s - lambda: |- id(learn_mode_off) = false; - platform: template name: "995) בדיקת הדלקה" on_press: then: - lambda: |- std::string code_to_send = std::bitset<21>(id(last_rf_code_on)).to_string(); ESP_LOGD("template", "Sending code: %s", code_to_send.c_str()); - remote_transmitter.transmit_rc_switch_raw: code: !lambda 'return std::bitset<21>(id(last_rf_code_on)).to_string();' protocol: 1 # !lambda 'return std::bitset<24>(id(last_rf_code_on)).to_string();' # !lambda 'return std::to_string(id(last_rf_code_on));' - platform: template name: "996) בדיקת כיבוי" on_press: then: - lambda: |- std::string code_to_send = std::bitset<21>(id(last_rf_code_off)).to_string(); ESP_LOGD("template", "Sending code: %s", code_to_send.c_str()); - remote_transmitter.transmit_rc_switch_raw: code: !lambda 'return std::bitset<21>(id(last_rf_code_off)).to_string();' protocol: 1 switch: - platform: template name: "41) הפעלת אוטומציית גנרטור" lambda: |- if (id(automation_shabbat_state)) { return true; } else { return false; } turn_on_action: - lambda: |- id(automation_shabbat_state) = true; turn_off_action: - lambda: |- id(automation_shabbat_state) = false; - platform: gpio name: "8) תאורה 1" pin: pcf8574: pcf8574_hub_out_1 number: 0 mode: OUTPUT inverted: true id: l1 - platform: gpio name: "9) תאורה 2" pin: pcf8574: pcf8574_hub_out_1 number: 1 mode: OUTPUT inverted: true id: l2 - platform: gpio name: "91) תאורה 3" pin: pcf8574: pcf8574_hub_out_1 number: 2 mode: OUTPUT inverted: true id: l3 - platform: gpio name: "92) תאורה 4" pin: pcf8574: pcf8574_hub_out_1 number: 3 mode: OUTPUT inverted: true id: l4 - platform: gpio name: "93) תאורה 5" pin: pcf8574: pcf8574_hub_out_1 number: 4 mode: OUTPUT inverted: true id: l5 - platform: gpio name: "94) תאורה 6" pin: pcf8574: pcf8574_hub_out_1 number: 5 mode: OUTPUT inverted: true id: l6 - platform: gpio name: "95) תאורה 7" pin: pcf8574: pcf8574_hub_out_1 number: 6 mode: OUTPUT inverted: true id: l7 - platform: gpio name: "96) מזגן" pin: pcf8574: pcf8574_hub_out_1 number: 7 mode: OUTPUT inverted: true id: ac binary_sensor: - platform: gpio name: "97) מפסק 1" pin: pcf8574: pcf8574_hub_in_1 number: 0 mode: INPUT inverted: true on_press: then: - switch.turn_on: l1 on_release: then: - switch.turn_off: l1 - platform: gpio name: "98) מפסק 2" pin: pcf8574: pcf8574_hub_in_1 number: 1 mode: INPUT inverted: true on_press: then: - switch.turn_on: l2 on_release: then: - switch.turn_off: l2 - platform: gpio name: "99) מפסק 3" pin: pcf8574: pcf8574_hub_in_1 number: 2 mode: INPUT inverted: true on_press: then: - switch.turn_on: l3 on_release: then: - switch.turn_off: l3 - platform: gpio name: "991) מפסק 4" pin: pcf8574: pcf8574_hub_in_1 number: 3 mode: INPUT inverted: true on_press: then: - switch.turn_on: l4 on_release: then: - switch.turn_off: l4 - platform: gpio name: "992) מפסק 5" pin: pcf8574: pcf8574_hub_in_1 number: 4 mode: INPUT inverted: true on_press: then: - switch.turn_on: l5 on_release: then: - switch.turn_off: l5 - platform: gpio name: "993) מפסק 6" pin: pcf8574: pcf8574_hub_in_1 number: 5 mode: INPUT inverted: true on_press: then: - switch.turn_on: l6 on_release: then: - switch.turn_off: l6 - platform: gpio pin: pcf8574: pcf8574_hub_in_1 number: 6 mode: INPUT inverted: true name: "994) מפסק 7" on_press: then: - switch.turn_on: l7 on_release: then: - switch.turn_off: l7 # - platform: gpio # pin: # pcf8574: pcf8574_hub_in_1 # number: 7 # mode: INPUT # inverted: true # name: "Input8" # - platform: gpio # name: "Input9" # pin: # number: 32 # inverted: true # - platform: gpio # name: "Input10" # pin: # number: 33 # inverted: true number: - platform: template name: "5) מתח הדלקת גנרטור" optimistic: true min_value: 11.9 max_value: 12.3 step: 0.1 id: lower_voltage_threshold initial_value: 12.1 - platform: template name: "6) מתח כיבוי גנרטור" optimistic: true min_value: 12.4 max_value: 14 step: 0.1 id: upper_voltage_threshold initial_value: 13.5 sensor: - platform: ina226 address: 0x40 # current: # name: "זרם המצבר" # power: # name: "KaravanBatery Power" bus_voltage: name: "7) מתח המצבר" id: KaravanBatery_Bus_Voltage on_value: - if: condition: lambda: |- return id(KaravanBatery_Bus_Voltage).state < id(lower_voltage_threshold).state && (id(automation_shabbat_state)) && (!id(on_executed)); then: - delay: 20s # Wait for 20 seconds - if: condition: lambda: |- return id(KaravanBatery_Bus_Voltage).state < id(lower_voltage_threshold).state && (id(automation_shabbat_state)) && (!id(on_executed)); then: - switch.turn_off: ac - delay: 3s - remote_transmitter.transmit_rc_switch_raw: code: !lambda 'return std::to_string(id(last_rf_code_on));' protocol: 1 - delay: 3s - switch.turn_on: ac - lambda: |- id(on_executed) = true; id(off_executed) = false; - if: condition: lambda: |- return id(KaravanBatery_Bus_Voltage).state > id(upper_voltage_threshold).state && (id(automation_shabbat_state)) && (!id(off_executed)); then: - delay: 20s # Wait for 20 seconds - if: condition: lambda: |- return id(KaravanBatery_Bus_Voltage).state > id(upper_voltage_threshold).state && (id(automation_shabbat_state)) && (!id(off_executed)); then: - switch.turn_off: ac - delay: 3s - remote_transmitter.transmit_rc_switch_raw: code: !lambda 'return std::to_string(id(last_rf_code_off));' protocol: 1 - delay: 3s - switch.turn_on: ac - lambda: |- id(off_executed) = true; id(on_executed) = false; # shunt_voltage: # name: "KaravanBatery Shunt Voltage" # max_current: 3.2A update_interval: 5s text_sensor: - platform: template name: "3) קוד הדלקה" id: rf_code_on lambda: |- return {std::to_string(id(last_rf_code_on))}; update_interval: 5s - platform: template name: "4) קוד כיבוי" id: rf_code_off lambda: |- return {std::to_string(id(last_rf_code_off))}; update_interval: 5s - platform: template name: "time now" id: time_text icon: mdi:clock-end lambda: |- auto esptime = id(sntp_time).now(); if(esptime.is_valid()) { auto esptime_text = esptime.strftime("%d.%m.%Y %H:%M"); return esptime_text; } else { return std::string("Invalid time"); } update_interval: 10s