Esphome p1meter victron version » Geschiedenis » Versie 4
Micha Kersloot, 10-07-2023 09:43
| 1 | 1 | Micha Kersloot | h1. Esphome p1meter victron version |
|---|---|---|---|
| 2 | |||
| 3 | 4 | Micha Kersloot | hardware: [[Esphome#p1-dsmr-power-meter-with-TTGO-T7-v13-mini]] |
| 4 | 2 | Micha Kersloot | based on https://github.com/NuKeMtje/ESPHomeDSMRVictron |
| 5 | and https://github.com/freakent/dbus-mqtt-devices is needed on the GX device. |
||
| 6 | |||
| 7 | 1 | Micha Kersloot | <pre> |
| 8 | substitutions: |
||
| 9 | name: p1meter |
||
| 10 | friendly_name: p1meter |
||
| 11 | |||
| 12 | esphome: |
||
| 13 | name: ${name} |
||
| 14 | friendly_name: ${friendly_name} |
||
| 15 | |||
| 16 | #esp8266: |
||
| 17 | # board: esp01_1m |
||
| 18 | # |
||
| 19 | |||
| 20 | esp32: |
||
| 21 | board: ttgo-t7-v13-mini32 |
||
| 22 | framework: |
||
| 23 | type: arduino |
||
| 24 | |||
| 25 | # Enable logging |
||
| 26 | logger: |
||
| 27 | # Serial logging is disabled by setting the logger baud rate to 0. |
||
| 28 | # Otherwise the logger will occupy the hardware UART, making it unavailable |
||
| 29 | # for receiving smart meter data on pin D7 (GPIO13). |
||
| 30 | baud_rate: 0 |
||
| 31 | |||
| 32 | # Enable Home Assistant API |
||
| 33 | api: |
||
| 34 | encryption: |
||
| 35 | 3 | Micha Kersloot | key: "xxxxxx" |
| 36 | 1 | Micha Kersloot | |
| 37 | ota: |
||
| 38 | 3 | Micha Kersloot | password: "xxxxxx" |
| 39 | 1 | Micha Kersloot | |
| 40 | wifi: |
||
| 41 | ssid: !secret wifi_ssid |
||
| 42 | password: !secret wifi_password |
||
| 43 | |||
| 44 | # Enable fallback hotspot (captive portal) in case wifi connection fails |
||
| 45 | ap: |
||
| 46 | ssid: "P1Meter Fallback Hotspot" |
||
| 47 | 3 | Micha Kersloot | password: "xxxxx" |
| 48 | 1 | Micha Kersloot | |
| 49 | captive_portal: |
||
| 50 | |||
| 51 | uart: |
||
| 52 | id: uart_bus |
||
| 53 | rx_pin: |
||
| 54 | # number: 3 |
||
| 55 | number: GPIO16 |
||
| 56 | inverted: true |
||
| 57 | baud_rate: 115200 |
||
| 58 | rx_buffer_size: 1700 |
||
| 59 | |||
| 60 | dsmr: |
||
| 61 | request_pin: GPIO19 |
||
| 62 | |||
| 63 | globals: |
||
| 64 | - id: portal_id |
||
| 65 | type: std::string |
||
| 66 | restore_value: no |
||
| 67 | initial_value: '"<not set>"' |
||
| 68 | - id: device_instance |
||
| 69 | type: std::string |
||
| 70 | restore_value: no |
||
| 71 | initial_value: '"<not set>"' |
||
| 72 | |||
| 73 | mqtt: |
||
| 74 | broker: venus |
||
| 75 | discovery: false |
||
| 76 | birth_message: |
||
| 77 | topic: device/p1mqtt/Status |
||
| 78 | payload: "{ \"clientId\": \"p1mqtt\", \"connected\": 1, \"version\": \"v1.0\", \"services\": {\"meter1\": \"grid\"} }" |
||
| 79 | will_message: |
||
| 80 | topic: device/p1mqtt/Status |
||
| 81 | payload: "{ \"clientId\": \"p1mqtt\", \"connected\": 0, \"services\": {\"meter1\": \"grid\"} }" |
||
| 82 | on_json_message: |
||
| 83 | topic: device/p1mqtt/DBus |
||
| 84 | then: |
||
| 85 | - lambda: |- |
||
| 86 | id(portal_id) = x["portalId"].as<std::string>(); |
||
| 87 | id(device_instance) = x["deviceInstance"]["meter1"].as<std::string>(); |
||
| 88 | - mqtt.publish_json: |
||
| 89 | topic: !lambda |- |
||
| 90 | return str_sprintf("W/%s/grid/%s/CustomName", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 91 | payload: |- |
||
| 92 | root["value"] = "P1-MQTT Meter"; |
||
| 93 | - mqtt.publish_json: |
||
| 94 | topic: !lambda |- |
||
| 95 | return str_sprintf("W/%s/grid/%s/Role", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 96 | payload: |- |
||
| 97 | root["value"] = "grid"; |
||
| 98 | |||
| 99 | sensor: |
||
| 100 | - platform: dsmr |
||
| 101 | energy_delivered_tariff1: |
||
| 102 | name: Energy Delivered Tariff 1 |
||
| 103 | id: energy_delivered_t1 |
||
| 104 | state_class: total_increasing |
||
| 105 | energy_delivered_tariff2: |
||
| 106 | name: Energy Delivered Tariff 2 |
||
| 107 | id: energy_delivered_t2 |
||
| 108 | state_class: total_increasing |
||
| 109 | energy_returned_tariff1: |
||
| 110 | name: Energy Returned Tariff 1 |
||
| 111 | id: energy_returned_t1 |
||
| 112 | energy_returned_tariff2: |
||
| 113 | name: Energy Returned Tariff 2 |
||
| 114 | id: energy_returned_t2 |
||
| 115 | power_delivered: |
||
| 116 | name: Power Consumed |
||
| 117 | id: power_consumed |
||
| 118 | power_returned: |
||
| 119 | name: Power Returned |
||
| 120 | id: power_returned |
||
| 121 | electricity_failures: |
||
| 122 | name: Electricity Failures |
||
| 123 | electricity_long_failures: |
||
| 124 | name: Electricity Long Failures |
||
| 125 | voltage_l1: |
||
| 126 | name: Voltage L1 |
||
| 127 | id: voltage_l1 |
||
| 128 | on_value: |
||
| 129 | then: |
||
| 130 | - mqtt.publish_json: |
||
| 131 | topic: !lambda |- |
||
| 132 | return str_sprintf("W/%s/grid/%s/Ac/L1/Voltage", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 133 | payload: |- |
||
| 134 | root["value"] = id(voltage_l1).state; |
||
| 135 | voltage_l2: |
||
| 136 | name: Voltage L2 |
||
| 137 | id: voltage_l2 |
||
| 138 | on_value: |
||
| 139 | then: |
||
| 140 | - mqtt.publish_json: |
||
| 141 | topic: !lambda |- |
||
| 142 | return str_sprintf("W/%s/grid/%s/Ac/L2/Voltage", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 143 | payload: |- |
||
| 144 | root["value"] = id(voltage_l2).state; |
||
| 145 | voltage_l3: |
||
| 146 | name: Voltage L3 |
||
| 147 | id: voltage_l3 |
||
| 148 | on_value: |
||
| 149 | then: |
||
| 150 | - mqtt.publish_json: |
||
| 151 | topic: !lambda |- |
||
| 152 | return str_sprintf("W/%s/grid/%s/Ac/L3/Voltage", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 153 | payload: |- |
||
| 154 | root["value"] = id(voltage_l3).state; |
||
| 155 | current_l1: |
||
| 156 | name: Current L1 |
||
| 157 | id: current_l1 |
||
| 158 | on_value: |
||
| 159 | then: |
||
| 160 | - mqtt.publish_json: |
||
| 161 | topic: !lambda |- |
||
| 162 | return str_sprintf("W/%s/grid/%s/Ac/L1/Current", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 163 | payload: |- |
||
| 164 | root["value"] = id(current_l1).state; |
||
| 165 | current_l2: |
||
| 166 | name: Current L2 |
||
| 167 | id: current_l2 |
||
| 168 | on_value: |
||
| 169 | then: |
||
| 170 | - mqtt.publish_json: |
||
| 171 | topic: !lambda |- |
||
| 172 | return str_sprintf("W/%s/grid/%s/Ac/L2/Current", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 173 | payload: |- |
||
| 174 | root["value"] = id(current_l2).state; |
||
| 175 | current_l3: |
||
| 176 | name: Current L3 |
||
| 177 | id: current_l3 |
||
| 178 | on_value: |
||
| 179 | then: |
||
| 180 | - mqtt.publish_json: |
||
| 181 | topic: !lambda |- |
||
| 182 | return str_sprintf("W/%s/grid/%s/Ac/L3/Current", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 183 | payload: |- |
||
| 184 | root["value"] = id(current_l3).state; |
||
| 185 | power_delivered_l1: |
||
| 186 | name: Power Delivered L1 |
||
| 187 | id: power_delivered_l1 |
||
| 188 | power_delivered_l2: |
||
| 189 | name: Power Delivered L2 |
||
| 190 | id: power_delivered_l2 |
||
| 191 | power_delivered_l3: |
||
| 192 | name: Power Delivered L3 |
||
| 193 | id: power_delivered_l3 |
||
| 194 | power_returned_l1: |
||
| 195 | name: Power Returned L1 |
||
| 196 | id: power_returned_l1 |
||
| 197 | power_returned_l2: |
||
| 198 | name: Power Returned L2 |
||
| 199 | id: power_returned_l2 |
||
| 200 | power_returned_l3: |
||
| 201 | name: Power Returned L3 |
||
| 202 | id: power_returned_l3 |
||
| 203 | gas_delivered: |
||
| 204 | name: Gas Delivered |
||
| 205 | - platform: template |
||
| 206 | name: "Total power" |
||
| 207 | id: total_power |
||
| 208 | lambda: |- |
||
| 209 | return (id(power_consumed).state - id(power_returned).state)*1000.0; |
||
| 210 | update_interval: 1s |
||
| 211 | device_class: power |
||
| 212 | state_class: measurement |
||
| 213 | unit_of_measurement: W |
||
| 214 | on_value: |
||
| 215 | then: |
||
| 216 | - mqtt.publish_json: |
||
| 217 | topic: !lambda |- |
||
| 218 | return str_sprintf("W/%s/grid/%s/Ac/Power", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 219 | payload: |- |
||
| 220 | root["value"] = id(total_power).state; |
||
| 221 | - platform: template |
||
| 222 | name: "Power L1" |
||
| 223 | id: power_l1 |
||
| 224 | lambda: |- |
||
| 225 | return (id(power_delivered_l1).state - id(power_returned_l1).state)*1000.0; |
||
| 226 | update_interval: 1s |
||
| 227 | device_class: power |
||
| 228 | state_class: measurement |
||
| 229 | unit_of_measurement: W |
||
| 230 | on_value: |
||
| 231 | then: |
||
| 232 | - mqtt.publish_json: |
||
| 233 | topic: !lambda |- |
||
| 234 | return str_sprintf("W/%s/grid/%s/Ac/L1/Power", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 235 | payload: |- |
||
| 236 | root["value"] = id(power_l1).state; |
||
| 237 | - platform: template |
||
| 238 | name: "Power L2" |
||
| 239 | id: power_l2 |
||
| 240 | lambda: |- |
||
| 241 | return (id(power_delivered_l2).state - id(power_returned_l2).state)*1000.0; |
||
| 242 | update_interval: 1s |
||
| 243 | device_class: power |
||
| 244 | state_class: measurement |
||
| 245 | unit_of_measurement: W |
||
| 246 | on_value: |
||
| 247 | then: |
||
| 248 | - mqtt.publish_json: |
||
| 249 | topic: !lambda |- |
||
| 250 | return str_sprintf("W/%s/grid/%s/Ac/L2/Power", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 251 | payload: |- |
||
| 252 | root["value"] = id(power_l2).state; |
||
| 253 | - platform: template |
||
| 254 | name: "Power L3" |
||
| 255 | id: power_l3 |
||
| 256 | lambda: |- |
||
| 257 | return (id(power_delivered_l3).state - id(power_returned_l3).state)*1000.0; |
||
| 258 | update_interval: 1s |
||
| 259 | device_class: power |
||
| 260 | state_class: measurement |
||
| 261 | unit_of_measurement: W |
||
| 262 | on_value: |
||
| 263 | then: |
||
| 264 | - mqtt.publish_json: |
||
| 265 | topic: !lambda |- |
||
| 266 | return str_sprintf("W/%s/grid/%s/Ac/L3/Power", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 267 | payload: |- |
||
| 268 | root["value"] = id(power_l3).state; |
||
| 269 | - platform: template |
||
| 270 | name: "Total consumed" |
||
| 271 | id: total_consumed |
||
| 272 | lambda: |- |
||
| 273 | return id(energy_delivered_t1).state + id(energy_delivered_t2).state; |
||
| 274 | update_interval: 1s |
||
| 275 | device_class: energy |
||
| 276 | state_class: total_increasing |
||
| 277 | unit_of_measurement: kWh |
||
| 278 | on_value: |
||
| 279 | then: |
||
| 280 | - mqtt.publish_json: |
||
| 281 | topic: !lambda |- |
||
| 282 | return str_sprintf("W/%s/grid/%s/Ac/Energy/Forward", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 283 | payload: |- |
||
| 284 | root["value"] = id(total_consumed).state; |
||
| 285 | - platform: template |
||
| 286 | name: "Total injected" |
||
| 287 | id: total_injected |
||
| 288 | lambda: |- |
||
| 289 | return id(energy_returned_t1).state + id(energy_returned_t2).state; |
||
| 290 | update_interval: 1s |
||
| 291 | device_class: energy |
||
| 292 | state_class: total_increasing |
||
| 293 | unit_of_measurement: kWh |
||
| 294 | on_value: |
||
| 295 | then: |
||
| 296 | - mqtt.publish_json: |
||
| 297 | topic: !lambda |- |
||
| 298 | return str_sprintf("W/%s/grid/%s/Ac/Energy/Reverse", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 299 | payload: |- |
||
| 300 | root["value"] = id(total_injected).state; |
||
| 301 | |||
| 302 | text_sensor: |
||
| 303 | - platform: dsmr |
||
| 304 | identification: |
||
| 305 | name: Identification |
||
| 306 | id: meter_id |
||
| 307 | on_value: |
||
| 308 | then: |
||
| 309 | - mqtt.publish_json: |
||
| 310 | topic: !lambda |- |
||
| 311 | return str_sprintf("W/%s/grid/%s/Serial", id(portal_id).c_str(), id(device_instance).c_str()); |
||
| 312 | payload: |- |
||
| 313 | root["value"] = id(meter_id).state; |
||
| 314 | p1_version: |
||
| 315 | name: Version |
||
| 316 | |||
| 317 | </pre> |