Http.post values of DSMR into external API

Hi,

I am trying to http post values of the esphome dsmr sensors from the esphome node into an external API

  • The API expects all 3 values to be posted at once:
  • All values need to be multiplied by 10.
curl -X 'POST' \
  'http://192.168.100.100/currents?L1=60&L2=70&L3=80' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{}'

The values from esphome (DSMR) I am trying to post:

sensor:
  - platform: dsmr
    current_l1:
      name: "$human_devicename - Current Phase 1"
    current_l2:
      name: "$human_devicename - Current Phase 2"
    current_l3:
      name: "$human_devicename - Current Phase 3"

I would like to post all 3 values into the API at once on any change of any of the 3 DSMR sensors.

What would be the best way to do that?

Cheers,

Michel

I have been trying a few options:

sensor:
  - platform: dsmr
    current_l1:
      name: "$human_devicename - Current Phase 1"
      id: current_l1
      on_value:
        then:
          - http_request.post:
              verify_ssl: false
              url: http://192.168.207.121/currents?
              json: |-
                root["L1"] = id(current_l1).state;
                root["L2"] = id(current_l2).state;
                root["L3"] = id(current_l3).state;

Which results in:

INFO Generating C++ source…
ERROR Circular dependency detected! Please run with -v option to see what functions failed to complete.

Then I tried:

sensor:
  - platform: dsmr
    current_l1:
      name: "$human_devicename - Current Phase 1"
      id: current_l1
    current_l2:
      name: "$human_devicename - Current Phase 2"
      id: current_l2
    current_l3:
      name: "$human_devicename - Current Phase 3"
      id: current_l3

time:
  - platform: sntp
    id: send_phase_data
    on_time:
      - seconds: 5
        then:
          - http_request.post:
              verify_ssl: false
              url: http://192.168.207.121/currents?
              json: |-
                root["L1"] = id(current_l1).state;
                root["L2"] = id(current_l2).state;
                root["L3"] = id(current_l3).state;

Which compiles, but does not return the correct data.

Then I tried:

time:
  - platform: sntp
    id: send_phase_data
    on_time:
      - seconds: 5
        then:
          - http_request.post:
              verify_ssl: false
              url: !lambda |-
                return ((std::string) "http://192.168.207.121/currents?L1=" + id(current_l1).state).c_str() + "&L2=" + id(current_l2).state).c_str() + "&L3=" + id(current_l3).state).c_str();

which returns:

/config/esphome/slimmelezer.yaml:261:67: error: no match for ‘operator+’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string’} and ‘float’)
261 | return ((std::string) “http://192.168.207.121/currents?L1=” + id(current_l1).state).c_str() + “&L2=” + id(current_l2).state).c_str() + “&L3=” + id(current_l3).state).c_str();

/config/esphome/slimmelezer.yaml:261:124: error: expected ‘;’ before ‘)’ token
261 | return ((std::string) “http://192.168.207.121/currents?L1=” + id(current_l1).state).c_str() + “&L2=” + id(current_l2).state).c_str() + “&L3=” + id(current_l3).state).c_str();
| ^
| ;
/config/esphome/slimmelezer.yaml:261:124: error: expected primary-expression before ‘)’ token
*** [/data/slimmelezer/.pioenvs/slimmelezer/src/main.cpp.o] Error 1
========================== [FAILED] Took 2.52 seconds ==========================

I obviously need some guidance :wink: