diff --git a/common.yaml b/common.yaml index e02a7248992bf3b8069d3fdfcb5711be9736f4ef..8cf9e2adfe49d3c6edf8b7bec1d47b19ec2173ac 100644 --- a/common.yaml +++ b/common.yaml @@ -4,6 +4,14 @@ esphome: project: name: $project_name version: $project_version + on_boot: + priority: -100 + then: + - lambda: |- + id(sntp_time).update(); + +preferences: + flash_write_interval: 0s logger: # level: INFO @@ -19,6 +27,7 @@ wifi: ssid: !secret wifi_ssid password: !secret wifi_password fast_connect: on + use_address: ${devicename}.${domain} ap: ssid: "$devicename Fallback Hotspot" password: !secret wifi_password @@ -30,8 +39,4 @@ web_server: local: true # include_internal: true -time: - - platform: sntp - id: sntp_time - prometheus: diff --git a/include/text_sensors.yaml b/include/text_sensors.yaml index 44ec329464370f0ab15f5fddddea1e81415ee195..3dea323068eee26842b03a4eed91819cd26457e1 100644 --- a/include/text_sensors.yaml +++ b/include/text_sensors.yaml @@ -10,3 +10,9 @@ name: "ESPHome Version" hide_timestamp: true +- platform: template + name: "Device Time" + lambda: |- + auto str_time = id(sntp_time).now().strftime("%d-%m-%Y %H:%M"); + return { str_time }; + update_interval: 60s diff --git a/propbox-fan.yaml b/propbox-fan.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2f388fad30a77d6d32f3dc01dab3bff26d30c282 --- /dev/null +++ b/propbox-fan.yaml @@ -0,0 +1,112 @@ +substitutions: + devicename: "propbox-fan" + domain: "faked.local" + comment: "Propagator Fan Control" + project_name: "groovy.propbox-fan" + project_version: "1.0" + + current_res: "0.00280" # Higher value gives lower watt readout + voltage_div: "775" # Lower value gives lower voltage readout + +<<: !include common.yaml + +esp8266: + board: esp8285 + +time: + - platform: sntp + id: sntp_time + timezone: "Europe/Berlin" + update_interval: 1h + +light: + - platform: status_led + id: "led_status" + pin: + number: GPIO13 + inverted: true + +binary_sensor: + # toggle relay on/off + - platform: gpio + id: "button_state" + pin: + number: GPIO00 + mode: INPUT_PULLUP + on_press: + - switch.toggle: "power" + +switch: + - platform: template + name: "Power" + optimistic: true + id: "power" + lambda: |- + if (id(relay).state) { + return true; + } else { + return false; + } + turn_on_action: + - switch.turn_on: "relay" + - light.turn_on: "led_status" + turn_off_action: + - switch.turn_off: "relay" + - light.turn_off: "led_status" + - platform: gpio + id: relay + pin: GPIO14 + +sensor: +### Default Sensors + + - platform: wifi_signal + name: "Wifi Signal" + update_interval: 60s + + - platform: uptime + name: "Uptime" + update_interval: 60s + +### Specific Sensors + + - platform: total_daily_energy + name: "Electric Consumption [kWh]" + power_id: "nous_a1t_watt" + filters: + # Multiplication factor from W to kW is 0.001 + - multiply: 0.001 + unit_of_measurement: kWh + + - platform: adc + pin: VCC + name: "VCC Volt" + + - platform: hlw8012 + sel_pin: + number: GPIO12 + inverted: True + cf_pin: GPIO04 + cf1_pin: GPIO05 + change_mode_every: 4 + current_resistor: ${current_res} + voltage_divider: ${voltage_div} + update_interval: 3s + + current: + name: "Ampere" + unit_of_measurement: A + accuracy_decimals: 3 + + voltage: + name: "Voltage" + unit_of_measurement: V + accuracy_decimals: 1 + + power: + name: "Power" + id: "nous_a1t_watt" + unit_of_measurement: W + +text_sensor: + !include include/text_sensors.yaml diff --git a/propbox-light.yaml b/propbox-light.yaml index 7a3c80da9c9e67b3b665c05b1ce4025ec44c6faf..47c5366e450a8c761074b72372cf221718913518 100644 --- a/propbox-light.yaml +++ b/propbox-light.yaml @@ -1,5 +1,6 @@ substitutions: devicename: "propbox-light" + domain: "faked.local" comment: "Propagator Light Control" project_name: "groovy.propbox-light" project_version: "1.0" @@ -12,6 +13,12 @@ substitutions: esp8266: board: esp8285 +time: + - platform: sntp + id: sntp_time + timezone: "Europe/Berlin" + update_interval: 1h + light: - platform: status_led id: "led_status" @@ -27,13 +34,13 @@ binary_sensor: number: GPIO00 mode: INPUT_PULLUP on_press: - - switch.toggle: "button_switch" + - switch.toggle: "power" switch: - platform: template - name: "Switch" + name: "Power" optimistic: true - id: "button_switch" + id: "power" lambda: |- if (id(relay).state) { return true; @@ -51,6 +58,8 @@ switch: pin: GPIO14 sensor: +### Default Sensors + - platform: wifi_signal name: "Wifi Signal" update_interval: 60s @@ -59,6 +68,8 @@ sensor: name: "Uptime" update_interval: 60s +### Specific Sensors + - platform: total_daily_energy name: "Electric Consumption [kWh]" power_id: "nous_a1t_watt" @@ -97,5 +108,5 @@ sensor: id: "nous_a1t_watt" unit_of_measurement: W -text_sensor: +text_sensor: !include include/text_sensors.yaml diff --git a/propbox.yaml b/propbox.yaml index aac58c03d34cff88b575788528061a91a47aea1b..aee0950d4ad86269bf52c3ab9a654ac2310f5549 100644 --- a/propbox.yaml +++ b/propbox.yaml @@ -1,10 +1,31 @@ substitutions: devicename: "propbox" + domain: "faked.local" comment: "Propagator Monitor" project_name: "groovy.propbox" project_version: "1.0" - sensor_mac: "A4:C1:38:47:14:50" + # Propbox Nodes + hostname_light: "propbox-light.${domain}" + hostname_fan: "propbox-fan.${domain}" + + # Sensors + ble_sensor_mac: "A4:C1:38:47:14:50" + + # Schedules + #schedule_grow_on: "0 0 3 * * *" + #schedule_grow_off: "0 0 21 * * *" + #schedule_bloom_on: "0 0 6 * * *" + #schedule_bloom_off: "0 0 18 * * *" + schedule_grow_on: "5,15,25,35,45,55 * * * * *" + schedule_grow_off: "0,10,20,30,40,50 * * * * *" + schedule_bloom_on: "0 * * * * *" + schedule_bloom_off: "30 * * * * *" + +# fix for 2022.5.0 +external_components: + - source: github://martgras/esphome@nvs-fix + components: [esp32] <<: !include common.yaml @@ -13,7 +34,9 @@ esp32: esp32_ble_tracker: -sensor: +sensor: +### Default Sensors + - platform: wifi_signal name: "Wifi Signal" update_interval: 60s @@ -22,16 +45,10 @@ sensor: name: "Uptime" update_interval: 60s - - platform: wifi_signal - name: "RSSI" - update_interval: 60s - - - platform: uptime - name: "Uptime" - update_interval: 60s +### Specific Sensors - platform: pvvx_mithermometer - mac_address: $sensor_mac + mac_address: $ble_sensor_mac temperature: name: "Temperature" humidity: @@ -41,4 +58,131 @@ sensor: battery_voltage: name: "Battery Voltage" -text_sensor: !include include/text_sensors.yaml +text_sensor: + !include include/text_sensors.yaml + +globals: + - id: schedule + type: int + restore_value: true + initial_value: '0' + - id: state_light + type: int + restore_value: true + initial_value: '0' + - id: state_fan + type: int + restore_value: true + initial_value: '0' + +select: + - platform: template + id: "select_schedule" + name: "Schedule" + options: + - "Disabled" + - "Grow" + - "Bloom" + optimistic: true + restore_value: true + on_value: + then: + - lambda: |- + auto index = id(select_schedule).active_index(); + id(schedule) = index.value(); + +http_request: + id: http_request_data + useragent: esphome/${devicename} + timeout: 10s + +switch: + - platform: template + id: "propbox_light" + name: "Light" + lambda: |- + if (id(state_light) == 1) { + return true; + } else { + return false; + } + turn_on_action: + - http_request.post: + url: http://${hostname_light}/switch/power/turn_on + on_response: + then: + - lambda: |- + if (status_code == 200) { + id(state_light) = 1; + } + turn_off_action: + - http_request.post: + url: http://${hostname_light}/switch/power/turn_off + on_response: + then: + - lambda: |- + if (status_code == 200) { + id(state_light) = 0; + } + - platform: template + id: "propbox_fan" + name: "Fan" + lambda: |- + if (id(state_fan) == 1) { + return true; + } else { + return false; + } + turn_on_action: + - http_request.post: + url: http://${hostname_fan}/switch/power/turn_on + on_response: + then: + - lambda: |- + if (status_code == 200) { + id(state_fan) = 1; + } + turn_off_action: + - http_request.post: + url: http://${hostname_fan}/switch/power/turn_off + on_response: + then: + - lambda: |- + if (status_code == 200) { + id(state_fan) = 0; + } + +time: + - platform: sntp + id: sntp_time + timezone: "Europe/Berlin" + update_interval: 1h + on_time: + - cron: $schedule_grow_on + then: + - lambda: |- + if (id(schedule) == 1) { + id(propbox_light).turn_on(); + id(state_light) = 1; + } + - cron: $schedule_grow_off + then: + - lambda: |- + if (id(schedule) == 1) { + id(propbox_light).turn_off(); + id(state_light) = 0; + } + - cron: $schedule_bloom_on + then: + - lambda: |- + if (id(schedule) == 2) { + id(propbox_light).turn_on(); + id(state_light) = 1; + } + - cron: $schedule_bloom_off + then: + - lambda: |- + if (id(schedule) == 2) { + id(propbox_light).turn_off(); + id(state_light) = 0; + }