Home Energy Management in 2021.8

I’m sorry, I won’t do it again

First of all you don’t have check if sensor.sdm120prod is > 0. The SDM120 should give you an always increasing number, it only adds up, so it can never go to 0.

You do have duplicates: you first use REST sensors and then use template sensors mirroring the value just to add state_class, but why? You can do everything with the REST sensor (read docs here):

- platform: rest
  name: "sdm120prod Energy Production"
  resource: http://xx.mywire.org:8080/api/last/SDM1.1
  value_template:  '{{ value_json.Import | float | round(2) }}'
  device_class: energy
  unit_of_measurement: 'kWh'
  state_class: total_increasing
  force_update: true
  
- platform: rest
  name: "sdm120scambio Energy Import"
  resource: http://xx.mywire.org:8080/api/last/SDM1.2
  value_template:  '{{ value_json.Import | float | round(2) }}'
  device_class: energy
  unit_of_measurement: 'kWh'
  state_class: total_increasing
  force_update: true
  
- platform: rest
  name: sdm120scambio Energy Export
  resource: http://xx.mywire.org:8080/api/last/SDM1.2
  value_template:  '{{ value_json.Export | float | round(2) }}'
  device_class: energy
  unit_of_measurement: 'kWh'
  state_class: total_increasing
  force_update: true

I didn’t check the code, so test it and let me know.

1 Like


That way it works and is much better to see

Simple is always better. :slight_smile:

I forgot one value, for each sensor: the polling period in seconds of the rest endpoint. The default is 30s.

scan_interval: 15
1 Like

Another thing I might suggest: you are using RESTful sensor, but if you want to pull more values for each call, you should switch to RESTful integration, read the docs here.

With restful, for each http call, you can define multiple sensors, so you can pull the other values the SDM120 provides: power, current, power factor, etc.

If you need help let me know.

1 Like

what does he do scan_interval: 15?

- platform: rest
  name: "sdm120scambio Energy Export"
  resource: http://xx.mywire.org:8080/api/last/SDM1.2
  value_template:  '{{ value_json.Export | float | round(2) }}'
  device_class: energy
  unit_of_measurement: 'kWh'
  state_class: total_increasing
  scan_interval: 15
  force_update: true

I told you in the post: it’s the frequency in seconds for the http request. So every X seconds HA calls http://xx.mywire.org to read the value. If you set it to 15, every 15 seconds the sensors are refreshed with the updated values. If you don’t specify it, the default is 30s.

1 Like

thanks for the tip, i want to try it myself first so i can learn. :wink:

ok, got it now

that’s how you learn, and that’s why I’m giving you the links to the docs. So you can experiment yourself.

Hint: the code for the sdm120 scambio can be done in one read instead of 2. :wink:

1 Like

perfect, and if you need anything very specific and not of interest to others, you can also message me privately on the forum, so you can freely use italian then. :slight_smile:

Ciao e buonanotte.

1 Like

I will update you with the progress in the coming days, ideas to put into practice I have many and I am only at the beginning

1 Like

Good morning,
i am trying to follow your advice and creating this:

rest:
  - authentication: basic
    scan_interval: 15
    resource: http://xx.mywire.org:8080/api/last/SDM1.1
    sensor:
      - name: "SDM120 Produzione Energy Import"
        value_template: '{{ value_json.Import | float | round(2) }}'
        device_class: energy
        unit_of_measurement: 'kWh'
        state_class: total_increasing
        force_update: true
  - authentication: basic
    scan_interval: 15
    resource: http://xx.mywire.org:8080/api/last/SDM1.2
    sensor:
      - name: "SDM120 Scambio Energy Import"
        value_template: '{{ value_json.Import | float | round(2) }}'
        device_class: energy
        unit_of_measurement: 'kWh'
        state_class: total_increasing
        force_update: true
      - name: "SDM120 Scambio Energy Export"
        value_template: '{{ value_json.Export | float | round(2) }}'
        device_class: energy
        unit_of_measurement: 'kWh'
        state_class: total_increasing
        force_update: true

I think I’m doing something wrong, because I had to insert it necessarily in the configuration.yaml file in the sensor gave me an error, why?
Thank you

rest:
  - authentication: basic
    scan_interval: 10
    resource: http://xx.mywire.org:8080/api/last/SDM1.1
    sensor:
      - name: "SDM120 Produzione Energy Power"
        value_template: '{{ value_json.PowerL1 | float | round(2) }}'
        device_class: power
        unit_of_measurement: 'Wh'
        state_class: measurement
        force_update: true
      - name: "SDM120 Produzione Energy Import"
        value_template: '{{ value_json.Import | float | round(2) }}'
        device_class: energy
        unit_of_measurement: 'kWh'
        state_class: total_increasing
        force_update: true
  - authentication: basic
    scan_interval: 10
    resource: http://xx.mywire.org:8080/api/last/SDM1.2
    sensor:
      - name: "SDM120 Scambio Energy Power"
        value_template: '{{ value_json.PowerL1 | float | round(2) }}'
        device_class: power
        unit_of_measurement: 'Wh'
        state_class: measurement
        force_update: true
      - name: "SDM120 Scambio Energy Import"
        value_template: '{{ value_json.Import | float | round(2) }}'
        device_class: energy
        unit_of_measurement: 'kWh'
        state_class: total_increasing
        force_update: true
      - name: "SDM120 Scambio Energy Export"
        value_template: '{{ value_json.Export | float | round(2) }}'
        device_class: energy
        unit_of_measurement: 'kWh'
        state_class: total_increasing
        force_update: true

in this way it is not possible to insert this, why?

icon: mdi:solar-power

Because if you want file configuration separation, you need to look at the platform used, in this case the platform is rest:.

So in config.yaml you put:

rest: !include rest.yaml

And in rest.yaml you put the contents that config.yaml pulls in, but without the platform label that is already specified:

- authentication: basic
  scan_interval: 15
  resource: http://xx.mywire.org:8080/api/last/SDM1.1
  sensor:
    - name: "SDM120 Produzione Energy Import"
      value_template: '{{ value_json.Import | float | round(2) }}'
      device_class: energy
      unit_of_measurement: 'kWh'
      state_class: total_increasing
      force_update: true
- authentication: basic
  scan_interval: 15
  resource: http://xx.mywire.org:8080/api/last/SDM1.2
  sensor:
    - name: "SDM120 Scambio Energy Import"
      value_template: '{{ value_json.Import | float | round(2) }}'
      device_class: energy
      unit_of_measurement: 'kWh'
      state_class: total_increasing
      force_update: true
    - name: "SDM120 Scambio Energy Export"
      value_template: '{{ value_json.Export | float | round(2) }}'
      device_class: energy
      unit_of_measurement: 'kWh'
      state_class: total_increasing
      force_update: true
1 Like

Because the REST platform doesn’t support the icon: config variable.

Did you read the docs as I advised? :wink:

If you really need to customize the icon, you can use customize:

Customizing entities - Home Assistant (home-assistant.io)

1 Like

Yes I have read the REST document and there is no icon in the list
but I also preferred to ask you.
It is not so necessary to customize the icons

The icons generally are derived from the device_class, but in many cases that icon is too generic. If you want to customize it you can, try from the UI, by clicking on the entity and customize the icon there.

Does the energy panel work now?

1 Like

Does the energy panel work now? Yes

Good job, and you learned a few things in the process. Have fun. :slight_smile:

1 Like