Project

Algemeen

Profiel

Esphome p1meter victron version » Geschiedenis » Revisie 2

Revisie 1 (Micha Kersloot, 27-06-2023 22:34) → Revisie 2/4 (Micha Kersloot, 28-06-2023 15:15)

h1. Esphome p1meter victron version 

 based on https://github.com/NuKeMtje/ESPHomeDSMRVictron 
 and https://github.com/freakent/dbus-mqtt-devices is needed on the GX device. 

 <pre> 
 substitutions: 
   name: p1meter 
   friendly_name: p1meter 

 


 esphome: 
   name: ${name} 
   friendly_name: ${friendly_name} 

 #esp8266: 
 #    board: esp01_1m 
 # 

 esp32: 
   board: ttgo-t7-v13-mini32 
   framework: 
     type: arduino 

 # Enable logging 
 logger: 
   # Serial logging is disabled by setting the logger baud rate to 0. 
   # Otherwise the logger will occupy the hardware UART, making it unavailable 
   # for receiving smart meter data on pin D7 (GPIO13). 
   baud_rate: 0 
  
 # Enable Home Assistant API 
 api: 
   encryption: 
     key: "qf1fx8kUj0uTiCK59UTTZalztwe8G1uZpOosMvvrV4E=" 

 ota: 
   password: "71b4ad566e816a7f8acb70e75ab94b21" 

 wifi: 
   ssid: !secret wifi_ssid 
   password: !secret wifi_password 

   # Enable fallback hotspot (captive portal) in case wifi connection fails 
   ap: 
     ssid: "P1Meter Fallback Hotspot" 
     password: "YPlPB0mxRpxD" 

 captive_portal: 
    
 uart: 
   id: uart_bus 
   rx_pin: 
 #      number: 3 
     number: GPIO16 
     inverted: true 
   baud_rate: 115200 
   rx_buffer_size: 1700 

 dsmr: 
   request_pin: GPIO19 

 globals: 
   - id: portal_id 
     type: std::string 
     restore_value: no 
     initial_value: '"<not set>"' 
   - id: device_instance 
     type: std::string 
     restore_value: no 
     initial_value: '"<not set>"' 

 mqtt: 
   broker: venus 
   discovery: false 
   birth_message: 
     topic: device/p1mqtt/Status 
     payload: "{ \"clientId\": \"p1mqtt\", \"connected\": 1, \"version\": \"v1.0\", \"services\": {\"meter1\": \"grid\"} }" 
   will_message: 
     topic: device/p1mqtt/Status 
     payload: "{ \"clientId\": \"p1mqtt\", \"connected\": 0, \"services\": {\"meter1\": \"grid\"} }" 
   on_json_message: 
     topic: device/p1mqtt/DBus 
     then: 
       - lambda: |- 
           id(portal_id) = x["portalId"].as<std::string>(); 
           id(device_instance) = x["deviceInstance"]["meter1"].as<std::string>(); 
       - mqtt.publish_json: 
           topic: !lambda |- 
             return str_sprintf("W/%s/grid/%s/CustomName", id(portal_id).c_str(), id(device_instance).c_str()); 
           payload: |- 
             root["value"] = "P1-MQTT Meter"; 
       - mqtt.publish_json: 
           topic: !lambda |- 
             return str_sprintf("W/%s/grid/%s/Role", id(portal_id).c_str(), id(device_instance).c_str()); 
           payload: |- 
             root["value"] = "grid"; 

 sensor: 
   - platform: dsmr 
     energy_delivered_tariff1: 
       name: Energy Delivered Tariff 1 
       id: energy_delivered_t1 
       state_class: total_increasing 
     energy_delivered_tariff2: 
       name: Energy Delivered Tariff 2 
       id: energy_delivered_t2 
       state_class: total_increasing 
     energy_returned_tariff1: 
       name: Energy Returned Tariff 1 
       id: energy_returned_t1 
     energy_returned_tariff2: 
       name: Energy Returned Tariff 2 
       id: energy_returned_t2 
     power_delivered: 
       name: Power Consumed 
       id: power_consumed 
     power_returned: 
       name: Power Returned 
       id: power_returned 
     electricity_failures: 
       name: Electricity Failures 
     electricity_long_failures: 
       name: Electricity Long Failures 
     voltage_l1: 
       name: Voltage L1 
       id: voltage_l1 
       on_value: 
         then: 
         - mqtt.publish_json: 
             topic: !lambda |- 
               return str_sprintf("W/%s/grid/%s/Ac/L1/Voltage", id(portal_id).c_str(), id(device_instance).c_str()); 
             payload: |- 
               root["value"] = id(voltage_l1).state; 
     voltage_l2: 
       name: Voltage L2 
       id: voltage_l2 
       on_value: 
         then: 
           - mqtt.publish_json: 
               topic: !lambda |- 
                 return str_sprintf("W/%s/grid/%s/Ac/L2/Voltage", id(portal_id).c_str(), id(device_instance).c_str()); 
               payload: |- 
                 root["value"] = id(voltage_l2).state; 
     voltage_l3: 
       name: Voltage L3 
       id: voltage_l3 
       on_value: 
         then: 
           - mqtt.publish_json: 
               topic: !lambda |- 
                 return str_sprintf("W/%s/grid/%s/Ac/L3/Voltage", id(portal_id).c_str(), id(device_instance).c_str()); 
               payload: |- 
                 root["value"] = id(voltage_l3).state; 
     current_l1: 
       name: Current L1 
       id: current_l1 
       on_value: 
         then: 
           - mqtt.publish_json: 
               topic: !lambda |- 
                 return str_sprintf("W/%s/grid/%s/Ac/L1/Current", id(portal_id).c_str(), id(device_instance).c_str()); 
               payload: |- 
                 root["value"] = id(current_l1).state; 
     current_l2: 
       name: Current L2 
       id: current_l2 
       on_value: 
         then: 
           - mqtt.publish_json: 
               topic: !lambda |- 
                 return str_sprintf("W/%s/grid/%s/Ac/L2/Current", id(portal_id).c_str(), id(device_instance).c_str()); 
               payload: |- 
                 root["value"] = id(current_l2).state; 
     current_l3: 
       name: Current L3 
       id: current_l3 
       on_value: 
         then: 
           - mqtt.publish_json: 
               topic: !lambda |- 
                 return str_sprintf("W/%s/grid/%s/Ac/L3/Current", id(portal_id).c_str(), id(device_instance).c_str()); 
               payload: |- 
                 root["value"] = id(current_l3).state; 
     power_delivered_l1: 
       name: Power Delivered L1 
       id: power_delivered_l1 
     power_delivered_l2: 
       name: Power Delivered L2 
       id: power_delivered_l2 
     power_delivered_l3: 
       name: Power Delivered L3 
       id: power_delivered_l3 
     power_returned_l1: 
       name: Power Returned L1 
       id: power_returned_l1 
     power_returned_l2: 
       name: Power Returned L2 
       id: power_returned_l2 
     power_returned_l3: 
       name: Power Returned L3 
       id: power_returned_l3 
     gas_delivered: 
       name: Gas Delivered 
   - platform: template 
     name: "Total power" 
     id: total_power 
     lambda: |- 
       return (id(power_consumed).state - id(power_returned).state)*1000.0; 
     update_interval: 1s 
     device_class: power 
     state_class: measurement 
     unit_of_measurement: W 
     on_value: 
       then: 
         - mqtt.publish_json: 
             topic: !lambda |- 
               return str_sprintf("W/%s/grid/%s/Ac/Power", id(portal_id).c_str(), id(device_instance).c_str()); 
             payload: |- 
               root["value"] = id(total_power).state; 
   - platform: template 
     name: "Power L1" 
     id: power_l1 
     lambda: |- 
       return (id(power_delivered_l1).state - id(power_returned_l1).state)*1000.0; 
     update_interval: 1s 
     device_class: power 
     state_class: measurement 
     unit_of_measurement: W 
     on_value: 
       then: 
         - mqtt.publish_json: 
             topic: !lambda |- 
               return str_sprintf("W/%s/grid/%s/Ac/L1/Power", id(portal_id).c_str(), id(device_instance).c_str()); 
             payload: |- 
               root["value"] = id(power_l1).state;     
   - platform: template 
     name: "Power L2" 
     id: power_l2 
     lambda: |- 
       return (id(power_delivered_l2).state - id(power_returned_l2).state)*1000.0; 
     update_interval: 1s 
     device_class: power 
     state_class: measurement 
     unit_of_measurement: W 
     on_value: 
       then: 
         - mqtt.publish_json: 
             topic: !lambda |- 
               return str_sprintf("W/%s/grid/%s/Ac/L2/Power", id(portal_id).c_str(), id(device_instance).c_str()); 
             payload: |- 
               root["value"] = id(power_l2).state; 
   - platform: template 
     name: "Power L3" 
     id: power_l3 
     lambda: |- 
       return (id(power_delivered_l3).state - id(power_returned_l3).state)*1000.0; 
     update_interval: 1s 
     device_class: power 
     state_class: measurement 
     unit_of_measurement: W 
     on_value: 
       then: 
         - mqtt.publish_json: 
             topic: !lambda |- 
               return str_sprintf("W/%s/grid/%s/Ac/L3/Power", id(portal_id).c_str(), id(device_instance).c_str()); 
             payload: |- 
               root["value"] = id(power_l3).state;                                        
   - platform: template 
     name: "Total consumed" 
     id: total_consumed 
     lambda: |- 
       return id(energy_delivered_t1).state + id(energy_delivered_t2).state; 
     update_interval: 1s 
     device_class: energy 
     state_class: total_increasing 
     unit_of_measurement: kWh 
     on_value: 
       then: 
         - mqtt.publish_json: 
             topic: !lambda |- 
               return str_sprintf("W/%s/grid/%s/Ac/Energy/Forward", id(portal_id).c_str(), id(device_instance).c_str()); 
             payload: |- 
               root["value"] = id(total_consumed).state;     
   - platform: template 
     name: "Total injected" 
     id: total_injected 
     lambda: |- 
       return id(energy_returned_t1).state + id(energy_returned_t2).state; 
     update_interval: 1s 
     device_class: energy 
     state_class: total_increasing 
     unit_of_measurement: kWh 
     on_value: 
       then: 
         - mqtt.publish_json: 
             topic: !lambda |- 
               return str_sprintf("W/%s/grid/%s/Ac/Energy/Reverse", id(portal_id).c_str(), id(device_instance).c_str()); 
             payload: |- 
               root["value"] = id(total_injected).state; 
        
 text_sensor: 
   - platform: dsmr 
     identification: 
       name: Identification 
       id: meter_id 
       on_value: 
         then: 
           - mqtt.publish_json: 
               topic: !lambda |- 
                 return str_sprintf("W/%s/grid/%s/Serial", id(portal_id).c_str(), id(device_instance).c_str()); 
               payload: |- 
                 root["value"] = id(meter_id).state; 
     p1_version: 
       name: Version 

 </pre>