S0 pulse output home assistant

Hi,

I think I’ve managed to make it work. I try to detail below what I’ve done, but don’t hesitate to ask me if anything is unclear.

I use a NodeMCU (8266) with ESPHome linked to a relay board with (at least) 3 relays. The first two relays are used to control the smart grid contact on the daikin altherma 3 heat pump (contacts 5-6 and 9-10 on the X5M connector on my model). This is the standard smart grid control detailed in different projects (see for instance ESPAltherma).

I then use the third relay (an optocoupler would be better but I didn’t have one available at the moment) and connect it to the Smart grid pulse meter input of the daikin heat pump (connectors 3-4 of the X5M connector on my model).

I use the following configuration for ESPhome:

esphome:
  name: espSmartGrid
  
  on_loop:
    then:
      - lambda: |-
          static uint32_t last_time = 0;
          static uint32_t start_pulse = 0;
          // 1000 imp/kWh =
          uint32_t pulse_width_ms = 1000*(3600*1000/1000)/(id(simu_power).state);
          uint32_t now = millis();

          if ((pulse_width_ms) > 0) {  
            if (now - last_time > (pulse_width_ms)) {
                last_time = now;
                start_pulse = now;
                id(out_power_pulse).turn_on();
                ESP_LOGD("loop", "pulse_width_ms: %d", (pulse_width_ms));
            }
          }

          if (now - start_pulse > id(pulse_duration).state) {
                id(out_power_pulse).turn_off();
          }
  
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: YourSSID
  password: YourPassword

api:

ota:

number:
  - platform: template
    id: simu_power
    name: "S0 Pulse Simulated Power"
    optimistic: true
    min_value: 0
    max_value: 4000
    step: 1
    initial_value: 0
  - platform: template
    id: pulse_duration
    name: "So Pulse Duration"
    optimistic: true
    min_value: 0
    max_value: 800
    step: 1
    initial_value: 200

output:
  - platform: gpio
    id: out_power_pulse
    pin: GPIO5
    inverted: true
  - platform: gpio
    id: relay_1
    pin: GPIO15
    inverted: true
  - platform: gpio
    id: relay_2
    pin: GPIO13
    inverted: true

select:
  - platform: template
    name: Smart Grid
    id: smart_grid
    options:
     - "Normal"
     - "Recommended On"
     - "Forced Off"
     - "Forced On"
    initial_option: "Normal"
    optimistic: true
    set_action:
      - logger.log:
          format: "Chosen option: %s"
          args: ["x.c_str()"]
    on_value:
      then:
      - lambda: |-
          if ( x == "Normal") {
            id(relay_1).turn_off();
            id(relay_2).turn_off();
          }
          else if ( x == "Recommended On") {
            id(relay_1).turn_on();
            id(relay_2).turn_off();
          }
          else if ( x == "Forced Off") {
            id(relay_1).turn_off();
            id(relay_2).turn_on();
          }
          else if ( x == "Forced On") {
            id(relay_1).turn_on();
            id(relay_2).turn_on();
          }

This configuration should generate a device with 3 entities:

  • one drop down which enable to select the smart grid setting (normal, recommended on, forced off, forced on)
  • a number input to enter the power value you want to simulate with the pulse (in watts)
  • a number input (default at 200 ms) to enter the length of the pulse you want to simulate (in ms)

when a power value other than 0 watts is entered, the ESP board starts to pulse the relay at the required frequency to generate 1000 pulses/ kWh.

On my ESP I use the GPIO 5, 13 and 15 to control the 3 relays, but you need to adapt this to the pins you use on your own board.

On the daikin the Smart Grid needs to be activated in the configuration:

  • “benefit kWh power supply” (menu item 9.8.4 for me) needs to be set to smart grid
  • “Limit setting kW” (menu item 9.8.8 for me) is on 0 (not sure this is really needed)
  • “Electricity meter 2” (menu item 9.A.2 for me) is set to “1000 pulses / kWh for PV panel”

Once you’ve plugged everything and configured a simulated power value, you need to let the pulse meter run for a good while (I think it took around 1h) for the heat pump to detect it. To check if it’s detected, you need to activate the smart grid to “recommended on” and then go to the information / operation modes menu to see what is the power limitation. Once it is detected, the heat pump seems to react well to changing the simulated power value (within 30 seconds here).

I’ve only managed to make it work today so maybe what is above will need to be adapted when I understand a bit better how it really works. Also at the moment I have not been able to test much since the heating / cooling is not needed here.

This is a very early test so what is above may not work well (or even at all) … and for the usual warning: if you tinker with your heat pump, there is risk of damage to it and I take no responsibility at all :sweat_smile:

The information above is mainly a compilation of the various posts I’ve read online from the ESPAltherma project , the P1P2MQTT project and from this post on ESPhome. Thanks to all of these super projects for enabling this fine control of my heat pump.