Pörssisähkö ohjaa kotia ilman nettiä – teksti-TV + Raspberry Pi
Osa 1: Pörssisähkö ohjaa kotia ILMAN nettiä – teksti TV + Raspberry Pi
Home Assistant ESP32 Robotti-imurin käynnistys releellä
ESP32n koodi:
esphome:
name: robot2
esp32:
board: mhetesp32minikit
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "LAITA_TÄHÄN_API_AVAIMESI"
ota:
- platform: esphome
password: "LAITA_TÄHÄN_OTA_SALASANASI"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.110
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Robot2 Fallback Hotspot"
password: "LAITA_TÄHÄN_HOTSPOT_SALASANASI"
captive_portal:
switch:
- platform: gpio
name: "KYTKINR2"
pin: 16
inverted: False
restore_mode: RESTORE_DEFAULT_OFF
Imurin automaatiot:
- id: '1742839773020'
alias: Robot 2 Start to vacum
description: ''
triggers:
- trigger: state
entity_id:
- input_button.start_vacuum
from:
conditions: []
actions:
- sequence:
- type: turn_on
device_id: f46a1851c8924e532596ac5cfc4f8356
entity_id: 7dba5e29c23b5cde41d06ef8e28ff155
domain: switch
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.kytkinr2
mode: single
- id: '1742840644556'
alias: Robot 2 time to clean
description: ''
triggers:
- trigger: time
at: input_datetime.robot_2_time
conditions:
- condition: template
value_template: '{{ now().weekday() in [3, 5] }}'
actions:
- action: automation.trigger
metadata: {}
data:
skip_condition: true
target:
entity_id: automation.robot_2_start_to_vacum
mode: single
Home Assistant ESP32 Liesituuletin
Huomasin jälkeenpäin, että sisääntulot on paras eristää optisesti. Liesikuvun rajakytkin ehti rikkoa suoraan kytketyn inputin, vaikka painike toimi moitteetta. Syynä on ilmeisesti mikrokytkimen huono suojaus ja siitä syntyvät ylijännitepiikit; pelkkä pulldown-vastus ei auttanut. Lisäsin sisääntulojen eteen releet, eikä häiriö enää pääse vaurioittamaan elektroniikkaa. Laitan myöhemmin kuvan kytkennästä.
ESP32n koodi:
esphome:
name: liesituuletin
friendly_name: Liesituuletin
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "LAITA_TÄHÄN_API_AVAIMESI"
ota:
- platform: esphome
password: "LAITA_TÄHÄN_OTA_SALASANASI"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.112
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Liesituuletin Fallback Hotspot"
password: "LAITA_TÄHÄN_HOTSPOT_SALASANASI"
captive_portal:
switch:
- platform: gpio
name: "LT-Valo"
pin: 32
inverted: False
restore_mode: RESTORE_DEFAULT_OFF
- platform: gpio
name: "LT-T1"
pin: 33
inverted: False
restore_mode: RESTORE_DEFAULT_OFF
- platform: gpio
name: "LT-T2"
pin: 25
inverted: False
restore_mode: RESTORE_DEFAULT_OFF
- platform: gpio
name: "LT-T3"
pin: 26
inverted: False
restore_mode: RESTORE_DEFAULT_OFF
binary_sensor:
- platform: gpio
pin:
number: 19
mode: INPUT_PULLUP
name: "Huuva"
device_class: opening
filters:
- invert:
- delayed_on: 50ms
- delayed_off: 50ms
- platform: gpio
pin:
number: 5
mode: INPUT_PULLUP
name: "Power"
device_class: opening
filters:
- invert:
- delayed_on: 50ms
- delayed_off: 50ms
sensor:
- platform: dht
pin: 21
model: DHT22
temperature:
name: "Lämpötila Huuva"
humidity:
name: "Kosteus Huuva"
update_interval: 6s
Liesituulettimen Automaatiot:
- id: '1745089202276'
alias: LIESI - Valo
description: ''
triggers:
- type: opened
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: cf2a5d78b221d1c674e4e7bc65f11d23
domain: binary_sensor
trigger: device
- type: not_opened
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: cf2a5d78b221d1c674e4e7bc65f11d23
domain: binary_sensor
trigger: device
conditions: []
actions:
- if:
- type: is_open
condition: device
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: cf2a5d78b221d1c674e4e7bc65f11d23
domain: binary_sensor
then:
- type: turn_on
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: a01b8a72147e981776abc67366f8f237
domain: switch
else:
- type: turn_off
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: a01b8a72147e981776abc67366f8f237
domain: switch
mode: single
- id: '1745091641469'
alias: LIESI - Syötön päälle laitto
description: ''
triggers:
- trigger: state
entity_id:
- binary_sensor.liesituuletin_huuva
from:
- trigger: state
entity_id:
- timer.liesi_aika
to: idle
- type: opened
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: 7d55476b80cf26df67250d12886baa9d
domain: binary_sensor
trigger: device
- type: not_opened
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: 7d55476b80cf26df67250d12886baa9d
domain: binary_sensor
trigger: device
conditions: []
actions:
- if:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.liesituuletin_huuva
state: 'on'
- type: is_temperature
condition: device
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: f57c06e691a2238beff9a2ecafa6cf2d
domain: sensor
below: 80
- condition: or
conditions:
- condition: state
entity_id: timer.liesi_aika
state: active
- type: is_open
condition: device
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: 7d55476b80cf26df67250d12886baa9d
domain: binary_sensor
then:
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.liesi
else:
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.liesi
mode: single
- id: '1745091959952'
alias: LIESI - TIMERI
description: ''
triggers:
- type: opened
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: cf2a5d78b221d1c674e4e7bc65f11d23
domain: binary_sensor
trigger: device
conditions: []
actions:
- action: timer.start
metadata: {}
data: {}
target:
entity_id: timer.liesi_aika
mode: single
- id: '1745093289166'
alias: LIESI - Kokkaaminen liian kallista, ylilämpö tai PALO
description: ''
triggers:
- trigger: state
entity_id:
- sensor.nordpool_kwh_fi_eur_10_10_0255
from:
- trigger: state
entity_id:
- sensor.liesituuletin_l_mp_tila_huuva
conditions: []
actions:
- if:
- condition: or
conditions:
- condition: numeric_state
entity_id: sensor.nordpool_kwh_fi_eur_10_10_0255
above: 0.2
- type: is_temperature
condition: device
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: f57c06e691a2238beff9a2ecafa6cf2d
domain: sensor
above: 60
- condition: and
conditions:
- type: is_temperature
condition: device
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: f57c06e691a2238beff9a2ecafa6cf2d
domain: sensor
above: 60
- type: is_humidity
condition: device
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: ab2fcf8c37206288024c8462112f52bf
domain: sensor
below: 1
alias: PALO
then:
- action: automation.turn_off
metadata: {}
data:
stop_actions: true
target:
entity_id:
- automation.liesi_paalle_laitto
- automation.liesi_timeri
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.liesi
else:
- action: automation.turn_on
metadata: {}
data: {}
target:
entity_id:
- automation.liesi_paalle_laitto
- automation.liesi_timeri
mode: single
- id: '1234567890'
alias: LIESI - LT1-3
description: Kytkee tuuletinnopeudet tarkkojen kosteustasojen mukaan
triggers:
- entity_id: sensor.liesituuletin_kosteus_huuva
trigger: state
- type: opened
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: cf2a5d78b221d1c674e4e7bc65f11d23
domain: binary_sensor
trigger: device
conditions: []
actions:
- if:
- type: is_open
condition: device
device_id: 1bec4ae8ee9a09c1148d7e626234df49
entity_id: cf2a5d78b221d1c674e4e7bc65f11d23
domain: binary_sensor
then:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.liesituuletin_kosteus_huuva
below: 48.9
sequence:
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id:
- switch.liesituuletin_lt_t1
- switch.liesituuletin_lt_t2
- switch.liesituuletin_lt_t3
- conditions:
- condition: numeric_state
entity_id: sensor.liesituuletin_kosteus_huuva
above: 49
below: 69.9
sequence:
- target:
entity_id: switch.liesituuletin_lt_t1
action: switch.turn_on
data: {}
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id:
- switch.liesituuletin_lt_t2
- switch.liesituuletin_lt_t3
- conditions:
- condition: numeric_state
entity_id: sensor.liesituuletin_kosteus_huuva
above: 70
below: 89.9
sequence:
- target:
entity_id: switch.liesituuletin_lt_t2
action: switch.turn_on
data: {}
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id:
- switch.liesituuletin_lt_t1
- switch.liesituuletin_lt_t3
- conditions:
- condition: numeric_state
entity_id: sensor.liesituuletin_kosteus_huuva
above: 90
sequence:
- target:
entity_id: switch.liesituuletin_lt_t3
action: switch.turn_on
data: {}
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id:
- switch.liesituuletin_lt_t1
- switch.liesituuletin_lt_t2
else:
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id:
- switch.liesituuletin_lt_t2
- switch.liesituuletin_lt_t1
- switch.liesituuletin_lt_t3
mode: single
Home Assistant ESP32 Liesituuletin ilman assistanttia Standalone
Tällä liesituuletin toimii ilman Home Assistanttia. Eli:
- Liesituuletin menee kosteuden mukaan eri asetuksiin
- Valo menee päälle, kun huuvan aukaisee ja menee pois päältä 60 minuutin päästä
- Lieden syöttö kannattaa tässä laittaa päälle, kun valo on päällä & huuva on auki & lämpötila on alle 50
- Tai jos haluat helpottaa asiaa, niin lieden syöttö on silloin päällä, kun valo on päällä.
esphome:
name: heatmoisture32
friendly_name: HeatMoisture32
esp32:
board: esp32dev
framework:
type: esp-idf
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "LAITA_TÄHÄN_API_AVAIMESI"
ota:
- platform: esphome
password: "LAITA_TÄHÄN_OTA_SALASANASI"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.116
gateway: 192.168.1.1
subnet: 255.255.255.0
ap:
ssid: "Heatmoisture32 Fallback Hotspot"
password: "LAITA_TÄHÄN_HOTSPOT_SALASANASI"
captive_portal:
# --- Muokkaa näitä arvoja yhdestä paikasta ---
globals:
- id: temp_threshold
type: float
initial_value: '21.0'
- id: humidity_threshold
type: float
initial_value: '60.0'
- id: temp_hysteresis
type: float
initial_value: '0.1'
- id: humidity_hysteresis
type: float
initial_value: '0.1'
# ------------------------------------------------
switch:
- platform: gpio
name: "vara"
pin: 17
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
id: vara_switch
- platform: gpio
name: "Kompura"
pin: 15
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
id: kompura_switch
- platform: gpio
name: "Heat"
pin: 18
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
id: heat_switch
- platform: gpio
name: "Start"
pin: 19
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
id: start_switch
- platform: template
name: "EN"
id: en_switch
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
sensor:
- platform: dht
pin: 21
model: DHT22
update_interval: 6s
temperature:
id: lampotila_HM
name: "Lämpötila HM"
humidity:
id: kosteus_HM
name: "Kosteus HM"
interval:
- interval: 6s
then:
- lambda: |-
const float temp = id(lampotila_HM).state;
const float hum = id(kosteus_HM).state;
const bool valid_temp = !isnan(temp);
const bool valid_hum = !isnan(hum);
if (!id(en_switch).state) {
id(start_switch).turn_off();
id(kompura_switch).turn_off();
id(heat_switch).turn_off();
return;
}
// HEAT: hysteresis
if (valid_temp) {
if (temp < (id(temp_threshold) - id(temp_hysteresis))) {
id(heat_switch).turn_on();
} else if (temp >= id(temp_threshold)) {
id(heat_switch).turn_off();
}
} else {
id(heat_switch).turn_off();
}
// KOMPURA: hysteresis
if (valid_hum) {
if (hum > (id(humidity_threshold) + id(humidity_hysteresis))) {
id(kompura_switch).turn_on();
} else if (hum <= id(humidity_threshold)) {
id(kompura_switch).turn_off();
}
} else {
id(kompura_switch).turn_off();
}
// START: päälle vain jos molemmat anturit kelvollisia ja HEAT tai KOMPURA on päällä
if (valid_temp && valid_hum && (id(heat_switch).state || id(kompura_switch).state)) {
id(start_switch).turn_on();
} else {
id(start_switch).turn_off();
}
Home Assistant ESP32, kosteuden poistaja ja lämmitin. Automaatio ESP:ssä ja lupa HomeAssistantista.
Katso video: Home Assistant + ESP32: Vanha kosteudenpoistaja älykkääksi ja sähköä säästäväksi
ESP32 wroom
esphome:
name: heatmoisture32
friendly_name: HeatMoisture32
esp32:
board: esp32dev
framework:
type: esp-idf
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "LAITA_TÄHÄN_API_AVAIMESI"
ota:
- platform: esphome
password: "LAITA_TÄHÄN_OTA_SALASANASI"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.116
gateway: 192.168.1.1
subnet: 255.255.255.0
ap:
ssid: "Heatmoisture32 Fallback Hotspot"
password: "LAITA_TÄHÄN_HOTSPOT_SALASANASI"
captive_portal:
# --- Muokkaa näitä arvoja yhdestä paikasta ---
globals:
- id: temp_threshold
type: float
initial_value: '21.0'
- id: humidity_threshold
type: float
initial_value: '60.0'
- id: temp_hysteresis
type: float
initial_value: '0.1'
- id: humidity_hysteresis
type: float
initial_value: '0.1'
# ------------------------------------------------
switch:
- platform: gpio
name: "vara"
pin: 17
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
id: vara_switch
- platform: gpio
name: "Kompura"
pin: 15
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
id: kompura_switch
- platform: gpio
name: "Heat"
pin: 18
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
id: heat_switch
- platform: gpio
name: "Start"
pin: 19
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
id: start_switch
- platform: template
name: "EN"
id: en_switch
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
sensor:
- platform: dht
pin: 21
model: DHT22
update_interval: 6s
temperature:
id: lampotila_HM
name: "Lämpötila HM"
humidity:
id: kosteus_HM
name: "Kosteus HM"
interval:
- interval: 6s
then:
- lambda: |-
const float temp = id(lampotila_HM).state;
const float hum = id(kosteus_HM).state;
const bool valid_temp = !isnan(temp);
const bool valid_hum = !isnan(hum);
if (!id(en_switch).state) {
id(start_switch).turn_off();
id(kompura_switch).turn_off();
id(heat_switch).turn_off();
return;
}
// HEAT: hysteresis
if (valid_temp) {
if (temp < (id(temp_threshold) - id(temp_hysteresis))) {
id(heat_switch).turn_on();
} else if (temp >= id(temp_threshold)) {
id(heat_switch).turn_off();
}
} else {
id(heat_switch).turn_off();
}
// KOMPURA: hysteresis
if (valid_hum) {
if (hum > (id(humidity_threshold) + id(humidity_hysteresis))) {
id(kompura_switch).turn_on();
} else if (hum <= id(humidity_threshold)) {
id(kompura_switch).turn_off();
}
} else {
id(kompura_switch).turn_off();
}
// START: päälle vain jos molemmat anturit kelvollisia ja HEAT tai KOMPURA on päällä
if (valid_temp && valid_hum && (id(heat_switch).state || id(kompura_switch).state)) {
id(start_switch).turn_on();
} else {
id(start_switch).turn_off();
}
Sitten pitää antaa ESP:een EN-switchille vain käsky HomeAssistantista, että se voi mennä päälle. Itse tein vain automaation, että kun sähkön hinta on kaikkinensa alle 0,15 senttiä, niin laite saa mennä päälle.
- id: '1761507912269'
alias: Kylpyhuoneen HM
description: ''
triggers:
- trigger: state
entity_id:
- sensor.nordpool_kwh_fi_eur_10_10_0255
conditions: []
actions:
- if:
- condition: numeric_state
entity_id: sensor.nordpool_kwh_fi_eur_10_10_0255
below: 0.15
then:
- type: turn_on
device_id: b00e27d77c9db2aa7f59fdbf30a7ef90
entity_id: a9b3d54df472cb0b4e12e6271041a1d7
domain: switch
else:
- type: turn_off
device_id: b00e27d77c9db2aa7f59fdbf30a7ef90
entity_id: a9b3d54df472cb0b4e12e6271041a1d7
domain: switch
mode: single
- id: '1761774163581'
alias: Restart
description: ''
triggers:
- trigger: time
at: '23:30:00'
weekday:
- sun
- mon
- tue
- wed
- thu
- fri
- sat
conditions: []
actions:
- action: hassio.host_reboot
metadata: {}
data: {}
mode: single
Home Assistant ESP32, WC, Standalone
Katso video: Home Assistant ESP32 vessan automatisointi
esphome:
name: wc1k
friendly_name: WC1k
on_boot:
priority: -100
then:
- delay: 10s
- lambda: |-
id(boot_ready) = true;
esp32:
board: esp32dev
framework:
type: esp-idf
logger:
api:
encryption:
key: "LAITA_TÄHÄN_API_AVAIMESI"
ota:
- platform: esphome
password: "LAITA_TÄHÄN_OTA_SALASANASI"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Wc1K Fallback Hotspot"
password: "LAITA_TÄHÄN_HOTSPOT_SALASANASI"
captive_portal:
i2c:
sda: 21
scl: 22
scan: true
id: bus_a
####################
# GLOBALS
####################
globals:
- id: boot_ready
type: bool
restore_value: no
initial_value: 'false'
- id: wc_kosteus
type: float
restore_value: no
initial_value: '0.0'
- id: wc_valo
type: float
restore_value: no
initial_value: '0.0'
- id: wc_ultra_osumat
type: int
restore_value: no
initial_value: '0'
- id: pistorasia_paalla
type: bool
restore_value: no
initial_value: 'false'
####################
# SENSORIT
####################
sensor:
- platform: bme680
i2c_id: bus_a
address: 0x77
update_interval: 10s
temperature:
name: "WC Lämpötila"
on_value:
then:
- if:
condition:
lambda: |-
return x < 22.0;
then:
- switch.turn_on: lattialammitys
else:
- switch.turn_off: lattialammitys
pressure:
name: "WC Ilmanpaine"
humidity:
name: "WC Kosteus"
on_value:
then:
- lambda: |-
id(wc_kosteus) = x;
- script.execute: paivita_pistorasia
- if:
condition:
lambda: |-
return x > 70.0;
then:
- switch.turn_on: poistopuhallus
else:
- switch.turn_off: poistopuhallus
gas_resistance:
name: "WC Kaasu"
- platform: adc
pin: 35
id: wc_valaistus_raw
name: "WC Valaistus RAW"
attenuation: 11db
update_interval: 100ms
filters:
- sliding_window_moving_average:
window_size: 3
on_value:
then:
- lambda: |-
id(wc_valo) = x;
- script.execute: paivita_pistorasia
- if:
condition:
lambda: |-
return !id(boot_ready);
then:
- switch.turn_off: musa1_chopinrain
- switch.turn_off: musa6_rain
- if:
condition:
lambda: |-
return id(boot_ready) && x > 0.5;
then:
- switch.turn_off: musa1_chopinrain
- switch.turn_off: musa6_rain
- if:
condition:
lambda: |-
return id(boot_ready) && x <= 0.5;
then:
- if:
condition:
switch.is_on: valo
then:
- switch.turn_off: musa6_rain
- switch.turn_on: musa1_chopinrain
else:
- switch.turn_off: musa1_chopinrain
- switch.turn_on: musa6_rain
- platform: pulse_width
pin: 34
id: wc_echo_raw
name: "WC Ultrasonic Echo Raw"
update_interval: 200ms
- platform: template
id: wc_echo_avg
name: "WC Ultrasonic Echo AVG"
update_interval: 200ms
lambda: |-
if (!id(wc_echo_raw).has_state()) return NAN;
float x = id(wc_echo_raw).state;
if (x < 0.0006 || x > 0.0030) return NAN;
return x;
filters:
- median:
window_size: 5
- sliding_window_moving_average:
window_size: 3
send_every: 1
on_value:
then:
- if:
condition:
lambda: |-
return id(boot_ready) && x < 0.0024;
then:
- lambda: |-
id(wc_ultra_osumat)++;
else:
- lambda: |-
id(wc_ultra_osumat) = 0;
- if:
condition:
lambda: |-
return id(wc_ultra_osumat) >= 3;
then:
- lambda: |-
id(wc_ultra_osumat) = 0;
- script.execute: valo_1min
####################
# ULTRAÄÄNI – TRIG
####################
interval:
- interval: 200ms
then:
- lambda: |-
id(jsn_trig).turn_on();
delayMicroseconds(10);
id(jsn_trig).turn_off();
####################
# SCRIPTIT
####################
script:
- id: valo_1min
mode: restart
then:
- switch.turn_on: valo
- delay: 60s
- switch.turn_off: valo
- id: paivita_pistorasia
mode: queued
then:
- lambda: |-
if (!id(boot_ready)) return;
if (!id(pistorasia_paalla)) {
if (id(wc_kosteus) < 63.0 && id(wc_valo) < 0.4) {
id(pistorasia_paalla) = true;
id(pistorasia).turn_on();
}
} else {
if (id(wc_kosteus) > 67.0 || id(wc_valo) > 0.5) {
id(pistorasia_paalla) = false;
id(pistorasia).turn_off();
}
}
####################
# KYTKIMET
####################
switch:
- platform: gpio
id: jsn_trig
internal: true
pin: 12
- platform: gpio
id: valo
name: "Valo"
pin: 25
restore_mode: RESTORE_DEFAULT_OFF
- platform: gpio
id: pistorasia
name: "Pistorasia"
pin: 26
restore_mode: ALWAYS_OFF
- platform: gpio
id: lattialammitys
name: "Lattialämmitys"
pin: 32
- platform: gpio
id: poistopuhallus
name: "Poistopuhallus"
pin: 33
####################
# MUSIIKIT (KAIKKI)
####################
- platform: gpio
id: musa1_chopinrain
name: "musa1_ChopinRain"
pin: 4
inverted: true
- platform: gpio
id: musa2_dune
name: "musa2_DUNE"
pin: 5
inverted: true
- platform: gpio
id: musa3_goddune
name: "musa3_GODdune"
pin: 16
inverted: true
- platform: gpio
id: musa4_interstellar
name: "musa4_Interstellar"
pin: 17
inverted: true
- platform: gpio
id: musa5_creepremix
name: "musa5_CreepRemix"
pin: 18
inverted: true
- platform: gpio
id: musa6_rain
name: "musa6_RAIN"
pin: 19
inverted: true
- platform: gpio
id: musa7_teknobathroom
name: "musa7_Teknobathroom2069"
pin: 23
inverted: true
- platform: gpio
id: musa8_tyler
name: "musa8_TylerPhilosophy"
pin: 27
inverted: true
Home Assistant Kello
Laita Configuration.yaml tiedostoon, niin saat kellon toimimaan:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
Home Assistant sähkön kustannussensori
Tällä saadaan päiväsähkö, yösähkö, ALV ja sähkön marginaali:
template:
- sensor:
- name: "Hetkellinen sähkön kustannus"
unit_of_measurement: "€/h"
state: >
{% set alv_kerroin = (states('input_number.alv') | float(25.5)) / 100 + 1 %}
{% set hinta = (states('sensor.nordpool_kwh_fi_eur_3_10_0') | float(0)) * alv_kerroin %}
{% set teho = states('sensor.p1_meter_power') | float(0) %}
{% set siirtohinta = states('input_number.yosahko') | float(0.035)
if now().hour >= 22 or now().hour < 6
else states('input_number.paivasahko') | float(0.045) %}
{% set marginaalihinta = (states('input_number.sahkon_marginaalihinta') | float(0)) * alv_kerroin %}
{{ ((hinta + siirtohinta + marginaalihinta) * teho) | round(4) }}
icon: mdi:currency-eur

Home Assistant APEX-kortti 48h Nordpool näkymä
type: custom:apexcharts-card
graph_span: 48h
apex_config:
chart:
height: 170px
show:
last_updated: true
experimental:
color_threshold: true
header:
title: NordPool+Siirto/kWh 48 h
show: true
show_states: true
colorize_states: true
span:
start: day
now:
show: true
label: Nyt
series:
- entity: sensor.nordpool_kwh_fi_eur_10_10_0255
show:
extremas: true
in_header: raw
header_color_threshold: true
type: column
data_generator: |
const today = entity.attributes.raw_today.map((start, index) => {
return [new Date(start["start"]).getTime(), Math.round(entity.attributes.raw_today[index]["value"] * 1000) / 1000];
});
const tomorrow = entity.attributes.raw_tomorrow
? entity.attributes.raw_tomorrow.map((start, index) => {
return [new Date(start["start"]).getTime(), Math.round(entity.attributes.raw_tomorrow[index]["value"] * 1000) / 1000];
})
: [];
return [...today, ...tomorrow];
float_precision: 3
color_threshold:
- value: 0
color: darkgreen
opacity: 1
- value: 0.1
color: goldenrod
- value: 0.32
color: darkred
yaxis:
- id: Hinta
min: ~0
decimals: 2
align_to: 0.05
show: true
Home Assistant RPI_GPIO HAT Raspberry pi
Tässä Raspberry pi:n 8 releiselle boardille
switch:
- platform: rpi_gpio
switches:
- port: 5
name: "KIUAS"
invert_logic: true
- port: 6
name: "LIESI"
invert_logic: true
- port: 13
name: "3-VAIHEPISTORASIA"
invert_logic: true
- port: 16
name: "ET 6 kW"
invert_logic: true
- port: 19
name: "ET 5,1 kW"
invert_logic: true
- port: 20
name: "ET 3,6 kWy"
invert_logic: true
- port: 21
name: "LVV"
invert_logic: true
- port: 26
name: "Öljypoltin"
invert_logic: true
Home Assistant Kustannussensori
Tässä templetti jossa yhdistetään kaikki kulut
template:
- sensor:
- name: "Hetkellinen sähkön kustannus"
unit_of_measurement: "€/h"
state: >
{% set alv_kerroin = (states('input_number.alv') | float(25.5)) / 100 + 1 %}
{% set hinta = (states('sensor.nordpool_kwh_fi_eur_3_10_0') | float(0)) * alv_kerroin %}
{% set teho = states('sensor.p1_meter_power') | float(0) %}
{% set siirtohinta = states('input_number.yosahko') | float(0.035)
if now().hour >= 22 or now().hour < 6
else states('input_number.paivasahko') | float(0.045) %}
{% set marginaalihinta = (states('input_number.sahkon_marginaalihinta') | float(0)) * alv_kerroin %}
{{ ((hinta + siirtohinta + marginaalihinta) * teho) | round(4) }}
icon: mdi:currency-eur
Silloin saat tuon uuden Hetkellisen sähkön kustannuksen ja luo nuo 4 eri helpperiä, että saat numerot templateen.
– input_number.paivasahko
– input_number.yosahko
– input_number.alv
– input_number.sahkon_marginaalihinta

Home Assistant ESP32 Pannun pumppujen ohjaus
Tässä templetti jossa yhdistetään kaikki kulut
esphome:
name: ljh
friendly_name: LJH
esp32:
board: esp32dev
framework:
type: esp-idf
logger:
# Näyttää web-sivulla, miksi laite on viimeksi käynnistynyt
debug:
update_interval: 60s
# Home Assistant API saa jäädä, mutta laite EI käynnisty
# uudelleen, vaikka Home Assistant ei olisi yhteydessä.
api:
reboot_timeout: 0s
encryption:
key: "LAITA_TÄHÄN_API_AVAIMESI"
# Koodin päivitys:
# - ESPHomella verkon yli
# - TAI lataamalla .ota.bin-tiedosto laitteen omalta web-sivulta
ota:
- platform: esphome
password: "LAITA_TÄHÄN_OTA_SALASANASI"
- platform: web_server
# IP-osoite tulee automaattisesti reitittimeltä (DHCP).
# Laitteeseen pääsee myös nimellä: http://ljh.local
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Laite jatkaa toimintaa, vaikka WiFi katkeaisi
reboot_timeout: 0s
ap:
ssid: "Ljh Fallback Hotspot"
password: "LAITA_TÄHÄN_HOTSPOT_SALASANASI"
captive_portal:
mdns:
# Oma web-käyttöliittymä (käyttäjä: admin)
web_server:
port: 80
version: 3
auth:
username: admin
password: "LAITA_TÄHÄN_WEB_SALASANASI"
sorting_groups:
- id: ryhma_asetukset
name: "🟡 SÄÄDÄ NÄITÄ 🟡"
sorting_weight: -10
- id: ryhma_laite
name: "Laite ja WiFi"
sorting_weight: 100
# ============================================================
# WIFI-VAIHTO JA LAITE (web-sivun alaosassa)
# ============================================================
# WiFi-verkon vaihto: täytä nämä ja paina "Vaihda WiFi"
text:
- platform: template
name: "Uusi WiFi nimi (SSID)"
id: uusi_ssid
optimistic: true
mode: text
max_length: 32
initial_value: ""
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 1
- platform: template
name: "Uusi WiFi salasana"
id: uusi_salasana
optimistic: true
mode: password
max_length: 64
initial_value: ""
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 2
button:
# Vaihtaa laitteen uuteen WiFi-verkkoon ja tallentaa tunnukset.
# Jos yhteys ei onnistu, laite palaa vanhaan verkkoon tai
# avaa varaverkon (Ljh Fallback Hotspot).
- platform: template
name: "Vaihda WiFi"
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 3
on_press:
- if:
condition:
lambda: 'return !id(uusi_ssid).state.empty();'
then:
- lambda: |-
id(wifi_tila).publish_state("Yhdistetään verkkoon " + id(uusi_ssid).state + "...");
- wifi.configure:
ssid: !lambda 'return id(uusi_ssid).state;'
password: !lambda 'return id(uusi_salasana).state;'
save: true
timeout: 30s
on_connect:
- lambda: |-
id(wifi_tila).publish_state("OK, yhdistetty verkkoon " + id(uusi_ssid).state);
on_error:
- lambda: |-
id(wifi_tila).publish_state("Virhe: verkkoon " + id(uusi_ssid).state + " ei saatu yhteyttä");
else:
- lambda: 'id(wifi_tila).publish_state("Anna ensin uuden verkon nimi");'
- platform: restart
name: "Käynnistä uudelleen"
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 10
text_sensor:
# Näyttää latauspumpun tilan, esim. "Käy, 42 min jäljellä" / "Pois"
- platform: template
id: pumpun_tila
name: "Latauspumpun tila"
update_interval: never
- platform: debug
reset_reason:
name: "Viimeisin käynnistyssyy"
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 7
- platform: template
name: "WiFi vaihdon tila"
id: wifi_tila
update_interval: never
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 4
- platform: wifi_info
ip_address:
name: "IP-osoite"
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 5
ssid:
name: "Nykyinen WiFi"
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 6
i2c:
sda: 21
scl: 22
scan: true
id: bus_a
# =========================================================
# HÄLYTYKSET JA TILA
# =========================================================
binary_sensor:
- platform: template
id: lisaapuut
name: "Lisää puuta pannuun"
- platform: template
id: anturi_vika
name: "Lämpötila-anturi vika"
# =========================================================
# SÄÄDETTÄVÄT ASETUKSET (web-sivulla, muistetaan sähkökatkon yli)
#
# TOIMINTA:
# Latauspumppu menee päälle VAIN, kun lämpötila nousee
# rajusti: vähintään "Käynnistysnousu" asteen verran
# "Nousun aikaikkuna" -ajan sisällä.
# Pumppu käy sen jälkeen "Käyntiaika"-minuutit ja sammuu.
# Jos käynnin aikana tulee uusi raju nousu (lisätty puuta),
# käyntiaika alkaa alusta.
#
# Pumppu EI mene päälle käynnistyksessä, anturiviassa
# eikä minkään rajan perusteella.
# =========================================================
number:
- platform: template
name: "🟡 Käyntiaika"
id: kayntiaika_min
unit_of_measurement: "min"
min_value: 5
max_value: 240
step: 5
initial_value: 60
optimistic: true
restore_value: true
mode: box
web_server:
sorting_group_id: ryhma_asetukset
sorting_weight: 1
- platform: template
name: "🟡 Käynnistysnousu"
id: nousuraja
unit_of_measurement: "°C"
min_value: 0.2
max_value: 5
step: 0.1
initial_value: 0.5
optimistic: true
restore_value: true
mode: box
web_server:
sorting_group_id: ryhma_asetukset
sorting_weight: 2
- platform: template
name: "🟡 Nousun aikaikkuna"
id: nousuikkuna_min
unit_of_measurement: "min"
min_value: 1
max_value: 10
step: 1
initial_value: 2
optimistic: true
restore_value: true
mode: box
web_server:
sorting_group_id: ryhma_asetukset
sorting_weight: 3
# =========================================================
# GLOBAALIT
# =========================================================
globals:
- id: last_ok_time
type: uint32_t
restore_value: no
initial_value: '0'
# Pumpun käynnin alkuhetki (millis), 0 = ei käynnissä
- id: kaynti_alku
type: uint32_t
restore_value: no
initial_value: '0'
# Korkein lukema käynnin aikana ("lisää puuta" -ilmoitusta varten)
- id: huippu
type: float
restore_value: no
initial_value: '0'
- id: low_temp_since
type: uint32_t
restore_value: no
initial_value: '0'
- id: lisaa_puuta_paalla
type: bool
restore_value: no
initial_value: 'false'
# =========================================================
# ANTURI JA OHJAUS
# =========================================================
sensor:
- platform: bme680
i2c_id: bus_a
address: 0x77
update_interval: 10s
temperature:
id: bme_temp
name: "BME680 Lampotila"
on_value:
then:
- lambda: |-
const uint32_t now = millis();
// Anturin kelvollisuus
if (isnan(x) || x < -40 || x > 200) {
id(anturi_vika).publish_state(true);
return; // pumppuun ei kosketa
}
id(last_ok_time) = now;
id(anturi_vika).publish_state(false);
// -----------------------------------------------
// Lukemahistoria (viimeiset ~10 min, 10 s välein)
// -----------------------------------------------
static const int N = 64;
static float hist_val[N];
static uint32_t hist_t[N];
static int hist_n = 0;
static int hist_pos = 0;
hist_val[hist_pos] = x;
hist_t[hist_pos] = now;
hist_pos = (hist_pos + 1) % N;
if (hist_n < N) hist_n++;
// Matalin lukema aikaikkunan sisällä
const uint32_t ikkuna = (uint32_t) id(nousuikkuna_min).state * 60000UL;
float minimi = x;
bool ikkuna_taynna = false;
for (int i = 0; i < hist_n; i++) {
int k = (hist_pos - 1 - i + N) % N;
uint32_t ika = now - hist_t[k];
if (ika <= ikkuna) {
if (hist_val[k] < minimi) minimi = hist_val[k];
} else {
ikkuna_taynna = true; // historiaa on koko ikkunan ajalta
}
}
// Käynnistyksen jälkeen odotetaan 5 min, koska anturi
// lämpenee itse ja antaisi väärän nousun.
const bool anturi_tasaantunut = now > 300000UL;
const bool raju_nousu =
anturi_tasaantunut && ikkuna_taynna &&
(x - minimi) >= id(nousuraja).state;
// -----------------------------------------------
// Pumppu
// -----------------------------------------------
if (raju_nousu) {
if (!id(P2).state) {
ESP_LOGI("ljh", "Raju nousu %.2f -> %.2f, pumppu päälle", minimi, x);
id(huippu) = x;
}
id(kaynti_alku) = now; // käyntiaika alkaa (uudelleen) alusta
id(P2).turn_on();
hist_n = 0; // sama nousu ei laukaise uudelleen
}
if (id(P2).state && x > id(huippu)) id(huippu) = x;
// -----------------------------------------------
// "Lisää puuta pannuun" (vain kun pumppu käy):
// lämpötila laskenut 0,3 °C huipusta tai alle 23 °C
// yli 5 minuuttia
// -----------------------------------------------
if (!id(P2).state) {
id(lisaa_puuta_paalla) = false;
id(low_temp_since) = 0;
} else {
if (id(huippu) - x >= 0.3f) id(lisaa_puuta_paalla) = true;
if (x < 23.0f) {
if (id(low_temp_since) == 0) id(low_temp_since) = now;
else if (now - id(low_temp_since) >= 300000UL) id(lisaa_puuta_paalla) = true;
} else {
id(low_temp_since) = 0;
}
if (raju_nousu) id(lisaa_puuta_paalla) = false;
}
id(lisaapuut).publish_state(id(lisaa_puuta_paalla));
ESP_LOGD("ljh", "T=%.2f min=%.2f nousu=%.2f P2=%s",
x, minimi, x - minimi, id(P2).state ? "ON" : "OFF");
pressure:
name: "BME680 Paine"
humidity:
name: "BME680 Kosteus"
gas_resistance:
name: "BME680 Kaasu"
# Kuinka kauan laite on ollut päällä. Jos tämä nollautuu
# usein, laite käynnistyy uudelleen (virta / WiFi / vika).
- platform: uptime
name: "Käynnissä"
update_interval: 60s
web_server:
sorting_group_id: ryhma_laite
sorting_weight: 8
# =========================================================
# AJASTIN JA TILA (10 s välein)
# =========================================================
interval:
- interval: 10s
then:
- lambda: |-
const uint32_t now = millis();
// Käyntiaika täynnä -> pumppu pois
const uint32_t kesto = (uint32_t) id(kayntiaika_min).state * 60000UL;
if (id(P2).state && (now - id(kaynti_alku)) >= kesto) {
ESP_LOGI("ljh", "Käyntiaika täynnä, pumppu pois");
id(P2).turn_off();
}
// Anturivalvonta (vain ilmoitus, pumppuun ei kosketa)
if (now - id(last_ok_time) > 30000UL) {
id(anturi_vika).publish_state(true);
}
// Tilarivi web-sivulle
std::string teksti;
if (id(P2).state) {
uint32_t kulunut = now - id(kaynti_alku);
int jaljella = kulunut >= kesto ? 0 : (int) ((kesto - kulunut + 59999UL) / 60000UL);
teksti = "Käy, " + to_string(jaljella) + " min jäljellä";
} else if (now < 300000UL) {
teksti = "Pois (anturi tasaantuu)";
} else {
teksti = "Pois";
}
if (id(anturi_vika).state) teksti += " - ANTURIVIKA";
if (teksti != id(pumpun_tila).state) id(pumpun_tila).publish_state(teksti);
# =========================================================
# RELEET
#
# P1 = Pattereiden kiertovesi (kuten ennenkin: päällä)
# P2 = Energiatankin latauspumppu
# Aina POIS käynnistyksessä. Menee päälle vain rajusta
# lämmön noususta tai käsin web-sivulta.
# =========================================================
switch:
- platform: gpio
id: P1
name: "Pattereiden kiertovesi"
pin: 25
restore_mode: ALWAYS_ON
- platform: gpio
id: P2
name: "Energiatankin latauspumppu"
pin: 26
restore_mode: ALWAYS_OFF
# Käsin päälle web-sivulta -> käy käyntiajan verran
on_turn_on:
- lambda: |-
if (id(kaynti_alku) == 0 || millis() - id(kaynti_alku) > 15000UL) {
id(kaynti_alku) = millis();
}
Home Assistant ESP32 Growatt invertterin Modbus
Growatt MOD 8000TL3-HU (käytetty DIN asenteista ESP32 laitetta, jossa oma rele)
esphome:
name: solar
friendly_name: Solar
esp32:
variant: esp32s3
flash_size: 16MB
framework:
type: esp-idf
logger:
level: DEBUG
api:
encryption:
key: "LAITA_TÄHÄN_API_AVAIMESI"
ota:
- platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Solar Fallback Hotspot"
password: "LAITA_TÄHÄN_HOTSPOT_SALASANASI"
captive_portal:
# ============================================================
# WAVESHARE ESP32-S3-RELAY-1CH
# ============================================================
#
# RS485:
# GPIO17 = TX
# GPIO18 = RX
# GPIO21 = RS485 direction / flow control
#
# Relay:
# GPIO47 = Relay
#
# ============================================================
# ============================================================
# UART / RS485
# ============================================================
uart:
id: mod_uart
tx_pin: GPIO17
rx_pin: GPIO18
# Growatt MOD 8000TL3-HU
baud_rate: 9600
data_bits: 8
parity: NONE
stop_bits: 1
rx_buffer_size: 256
# ============================================================
# MODBUS
# ============================================================
modbus:
id: mod_bus
uart_id: mod_uart
# Waveshare ESP32-S3-Relay-1CH RS485 direction control
flow_control_pin: GPIO21
# If Modbus becomes unstable, try:
# send_wait_time: 1s
# turnaround_time: 500ms
send_wait_time: 500ms
turnaround_time: 200ms
# ============================================================
# GROWATT MOD 8000TL3-HU
# ============================================================
#
# Growatt 33000-series input registers are used here as raw
# ESPHome addresses by subtracting 30000.
#
# Example:
# Growatt register 33023 -> ESPHome address 3023
#
# Runtime values are read as input registers.
#
# ============================================================
modbus_controller:
- id: growatt
address: 0x01
modbus_id: mod_bus
setup_priority: -10
update_interval: 5s
offline_skip_updates: 2
on_online:
then:
- logger.log: "Growatt Modbus ONLINE"
on_offline:
then:
- logger.log: "Growatt Modbus OFFLINE"
# ============================================================
# SWITCHES
# ============================================================
switch:
- platform: gpio
name: "Solar Relay"
id: solar_relay
pin:
number: GPIO47
inverted: false
restore_mode: ALWAYS_OFF
- platform: gpio
name: "Solar Test GPIO1"
id: test_gpio1
pin:
number: GPIO1
inverted: false
restore_mode: ALWAYS_OFF
- platform: gpio
name: "Solar Test GPIO2"
id: test_gpio2
pin:
number: GPIO2
inverted: false
restore_mode: ALWAYS_OFF
# ============================================================
# TEXT SENSORS
# ============================================================
text_sensor:
- platform: template
name: "Solar Inverter Status"
id: solar_inverter_status_text
update_interval: 5s
lambda: |-
if (!id(growatt_status_code).has_state()) {
return {"Unknown"};
}
switch ((int) id(growatt_status_code).state) {
case 0:
return {"Waiting"};
case 1:
return {"Normal"};
case 3:
return {"Fault"};
default:
return {"Unknown"};
}
- platform: template
name: "Solar Modbus Connection"
id: solar_modbus_connection
update_interval: 10s
lambda: |-
if (id(growatt_status_code).has_state()) {
return {"ONLINE"};
}
return {"OFFLINE"};
# ============================================================
# SENSORS
# ============================================================
sensor:
# ============================================================
# BASIC STATUS
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3000
name: "Solar Growatt Status Code"
id: growatt_status_code
register_type: input
value_type: U_WORD
accuracy_decimals: 0
# ============================================================
# PV INPUT
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3001
name: "Solar PV Input Power"
id: solar_pv_input_power
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# PV1
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3003
name: "Solar PV1 Voltage"
id: solar_pv1_voltage
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3004
name: "Solar PV1 Current"
id: solar_pv1_current
register_type: input
value_type: U_WORD
unit_of_measurement: "A"
device_class: current
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3005
name: "Solar PV1 Power"
id: solar_pv1_power
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# PV2
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3007
name: "Solar PV2 Voltage"
id: solar_pv2_voltage
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3008
name: "Solar PV2 Current"
id: solar_pv2_current
register_type: input
value_type: U_WORD
unit_of_measurement: "A"
device_class: current
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3009
name: "Solar PV2 Power"
id: solar_pv2_power
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# SOLAR AC OUTPUT POWER - RAW
# ============================================================
#
# Raw inverter AC output power.
# Internal only, not exposed to Home Assistant.
#
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3023
name: "Solar AC Power Raw"
id: solar_ac_power_raw
internal: true
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# SOLAR AC OUTPUT POWER - CLEAN
# ============================================================
#
# Home Assistant Energy Dashboard:
# Solar production power -> Solar AC Power
#
# Logic:
# - If PV input is near zero, report 0 W.
# - If raw inverter value is impossible for 8 kW inverter, ignore it.
# - Otherwise pass through raw value.
#
# ============================================================
- platform: template
name: "Solar AC Power"
id: solar_ac_power
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 5s
lambda: |-
if (!id(solar_ac_power_raw).has_state()) {
return 0.0;
}
float raw = id(solar_ac_power_raw).state;
float pv = 0.0;
if (id(solar_pv_input_power).has_state()) {
pv = id(solar_pv_input_power).state;
}
// If PV input is basically zero, the inverter should not be producing.
// This prevents stale daytime values from showing at night.
if (pv < 50.0) {
return 0.0;
}
// 8 kW inverter should never report values anywhere near this.
if (raw < 0.0 || raw > 12000.0) {
return {};
}
return raw;
# ============================================================
# AC FREQUENCY
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3025
name: "Solar AC Frequency"
id: solar_ac_frequency
register_type: input
value_type: U_WORD
unit_of_measurement: "Hz"
device_class: frequency
state_class: measurement
accuracy_decimals: 2
filters:
- multiply: 0.01
# ============================================================
# AC L1
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3026
name: "Solar AC Voltage L1"
id: solar_ac_voltage_l1
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3027
name: "Solar AC Current L1"
id: solar_ac_current_l1
register_type: input
value_type: U_WORD
unit_of_measurement: "A"
device_class: current
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3028
name: "Solar AC Power L1"
id: solar_ac_power_l1
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# AC L2
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3030
name: "Solar AC Voltage L2"
id: solar_ac_voltage_l2
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3031
name: "Solar AC Current L2"
id: solar_ac_current_l2
register_type: input
value_type: U_WORD
unit_of_measurement: "A"
device_class: current
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3032
name: "Solar AC Power L2"
id: solar_ac_power_l2
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# AC L3
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3034
name: "Solar AC Voltage L3"
id: solar_ac_voltage_l3
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3035
name: "Solar AC Current L3"
id: solar_ac_current_l3
register_type: input
value_type: U_WORD
unit_of_measurement: "A"
device_class: current
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3036
name: "Solar AC Power L3"
id: solar_ac_power_l3
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# LINE VOLTAGES
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3038
name: "Solar AC Voltage L1-L2"
id: solar_ac_voltage_l1_l2
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3039
name: "Solar AC Voltage L2-L3"
id: solar_ac_voltage_l2_l3
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3040
name: "Solar AC Voltage L3-L1"
id: solar_ac_voltage_l3_l1
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# GRID IMPORT POWER - RAW
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3041
name: "Grid Import Power Raw"
id: grid_import_power_raw
internal: true
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# GRID IMPORT POWER - CLEAN
# ============================================================
- platform: template
name: "Grid Import Power"
id: grid_import_power
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 5s
lambda: |-
if (!id(grid_import_power_raw).has_state()) {
return 0.0;
}
float raw = id(grid_import_power_raw).state;
if (raw < 0.0 || raw > 30000.0) {
return {};
}
return raw;
# ============================================================
# GRID EXPORT POWER - RAW
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3043
name: "Grid Export Power Raw"
id: grid_export_power_raw
internal: true
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# GRID EXPORT POWER - CLEAN
# ============================================================
- platform: template
name: "Grid Export Power"
id: grid_export_power
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 5s
lambda: |-
if (!id(grid_export_power_raw).has_state()) {
return 0.0;
}
float raw = id(grid_export_power_raw).state;
if (raw < 0.0 || raw > 30000.0) {
return {};
}
return raw;
# ============================================================
# HOME LOAD POWER - RAW
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3045
name: "Home Load Power Raw"
id: home_load_power_raw
internal: true
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# HOME LOAD POWER - CLEAN
# ============================================================
- platform: template
name: "Home Load Power"
id: home_load_power
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 5s
lambda: |-
if (!id(home_load_power_raw).has_state()) {
return 0.0;
}
float raw = id(home_load_power_raw).state;
if (raw < 0.0 || raw > 30000.0) {
return {};
}
return raw;
# ============================================================
# OPERATING TIME
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3047
name: "Solar Inverter Operating Time"
id: solar_inverter_operating_time
register_type: input
value_type: U_DWORD
unit_of_measurement: "s"
state_class: total_increasing
accuracy_decimals: 0
filters:
- multiply: 0.5
# ============================================================
# SOLAR AC ENERGY
# ============================================================
#
# These are the inverter's own energy counters.
#
# Home Assistant Energy Dashboard:
# Solar production energy -> Solar AC Energy Lifetime
#
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3049
name: "Solar AC Energy Today"
id: solar_ac_energy_today
register_type: input
value_type: U_DWORD
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3051
name: "Solar AC Energy Lifetime"
id: solar_ac_energy_lifetime
register_type: input
value_type: U_DWORD
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# PV ENERGY
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3053
name: "Solar PV Energy Total"
id: solar_pv_energy_total
register_type: input
value_type: U_DWORD
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3055
name: "Solar PV1 Energy Today"
id: solar_pv1_energy_today
register_type: input
value_type: U_DWORD
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3057
name: "Solar PV1 Energy Total"
id: solar_pv1_energy_total
register_type: input
value_type: U_DWORD
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3059
name: "Solar PV2 Energy Today"
id: solar_pv2_energy_today
register_type: input
value_type: U_DWORD
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3061
name: "Solar PV2 Energy Total"
id: solar_pv2_energy_total
register_type: input
value_type: U_DWORD
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# INSULATION AND TEMPERATURES
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3087
name: "Solar PV Insulation"
id: solar_pv_insulation
register_type: input
value_type: U_WORD
unit_of_measurement: "kOhm"
accuracy_decimals: 0
- platform: modbus_controller
modbus_controller_id: growatt
address: 3093
name: "Solar Inverter IPM Temperature"
id: solar_inverter_ipm_temperature
register_type: input
value_type: U_WORD
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3094
name: "Solar Inverter Temperature"
id: solar_inverter_temperature
register_type: input
value_type: U_WORD
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3095
name: "Solar Boost Temperature"
id: solar_boost_temperature
register_type: input
value_type: U_WORD
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3097
name: "Solar Communication Board Temperature"
id: solar_communication_board_temperature
register_type: input
value_type: U_WORD
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# BUS VOLTAGES
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3098
name: "Solar P Bus Voltage"
id: solar_p_bus_voltage
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: growatt
address: 3099
name: "Solar N Bus Voltage"
id: solar_n_bus_voltage
register_type: input
value_type: U_WORD
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# POWER FACTOR AND LIMITS
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3100
name: "Solar Inverter Power Factor"
id: solar_inverter_power_factor
register_type: input
value_type: U_WORD
device_class: power_factor
accuracy_decimals: 3
filters:
- multiply: 0.001
- platform: modbus_controller
modbus_controller_id: growatt
address: 3101
name: "Solar Output Power Percent"
id: solar_output_power_percent
register_type: input
value_type: U_WORD
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: modbus_controller
modbus_controller_id: growatt
address: 3102
name: "Solar Output Power Limit"
id: solar_output_power_limit
register_type: input
value_type: U_DWORD
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
- multiply: 0.1
# ============================================================
# FAULT AND WARNING CODES
# ============================================================
- platform: modbus_controller
modbus_controller_id: growatt
address: 3105
name: "Solar Growatt Fault Code"
id: solar_growatt_fault_code
register_type: input
value_type: U_WORD
accuracy_decimals: 0
- platform: modbus_controller
modbus_controller_id: growatt
address: 3106
name: "Solar Growatt Warning Code"
id: solar_growatt_warning_code
register_type: input
value_type: U_WORD
accuracy_decimals: 0
# ============================================================
# GRID ENERGY FROM POWER INTEGRATION
# ============================================================
#
# These are calculated from cleaned instantaneous grid import/export power.
#
# Home Assistant Energy Dashboard:
# Energy imported from grid -> Grid Import Energy
# Energy exported to grid -> Grid Export Energy
#
# Note:
# restore: false avoids bringing back old broken offsets.
# If everything looks stable for a few days, this can be changed to true.
#
# ============================================================
- platform: integration
name: "Grid Import Energy"
id: grid_import_energy
sensor: grid_import_power
time_unit: h
integration_method: trapezoid
restore: false
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 3
filters:
- multiply: 0.001
- platform: integration
name: "Grid Export Energy"
id: grid_export_energy
sensor: grid_export_power
time_unit: h
integration_method: trapezoid
restore: false
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 3
filters:
- multiply: 0.001
# ============================================================
# LOAD ENERGY DEBUG
# ============================================================
#
# Not needed for Energy Dashboard grid connection.
# Useful for your own debugging.
#
# ============================================================
- platform: integration
name: "Home Load Energy"
id: home_load_energy
sensor: home_load_power
time_unit: h
integration_method: trapezoid
restore: false
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
accuracy_decimals: 3
filters:
- multiply: 0.001
# ============================================================
# DEBUG / SANITY CHECK SENSORS
# ============================================================
- platform: template
name: "Solar PV To AC Difference"
id: solar_pv_to_ac_difference
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 5s
lambda: |-
if (!id(solar_pv_input_power).has_state() || !id(solar_ac_power).has_state()) {
return NAN;
}
return id(solar_pv_input_power).state - id(solar_ac_power).state;
- platform: template
name: "Solar Calculated Home Load"
id: solar_calculated_home_load
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 5s
lambda: |-
if (
!id(solar_ac_power).has_state() ||
!id(grid_import_power).has_state() ||
!id(grid_export_power).has_state()
) {
return NAN;
}
return id(solar_ac_power).state + id(grid_import_power).state - id(grid_export_power).state;
- platform: template
name: "Solar Power Balance Error"
id: solar_power_balance_error
unit_of_measurement: "W"
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 5s
lambda: |-
if (
!id(home_load_power).has_state() ||
!id(solar_calculated_home_load).has_state()
) {
return NAN;
}
return id(home_load_power).state - id(solar_calculated_home_load).state;
