MyStrom Smart Switch in Energy Consumption Overview Page

HI @pixelwave,

Thanks for sharing, I am trying to make sense of the configuration you put together. How do the different section relate together? In the power output you refer to switch.mystrom_switch but you didn’t quite define that as an ID anywhere, is it automatically inferred from the platform, similarly you refer to the sensor.energy_consumption without really having defined it elsewhere.
Maybe I am missing some basic understanding of the templating, I could likely grasp it, if you could share on your concrete example.

Thanks
Yvan

DISCLAIMER I am not an expert but here is my “believe” … :wink: DISCLAIMER

In the power output you refer to switch.mystrom_switch but you didn’t quite define that as an ID anywhere, is it automatically inferred from the platform

Yes that is created by the myStrom integration:

# Custom Switches
switch:
  # MyStrom Switch
  - platform: mystrom
    host: 192.168.178.23

…similarly you refer to the sensor.energy_consumption without really having defined it elsewhere.

That sensor is created here:

  # MyStrom Switch - Consumption Output (kWh)
  - platform: integration
    source: sensor.power
    name: "Energy Consumption"
    unit_prefix: k
    round: 3
    #unit: kWh

… since I am not an expert I sometimes mix and match code-snippets from different sources until it works. So this is just a different way I guess of defining a sensor. The name sensor.energy_consumption is derived from the friendly name automatically in line: name: “Energy Consumption”.

Hope that helps somehow … ^^

1 Like

Thanks it does help quite a bit, I’ll give it a try!

I have found an easyer way to implement the mystrom power plug in to the energy dashboard.

 - platform: rest
    resource: http://192.168.x.xx/report
    value_template: "{{ value_json.power | round(1) }}"
    name: "Power Mystrom"
    unit_of_measurement: W
    device_class: power

  - platform: integration
    source: sensor.power_mystrom
    name: "Energy Consumption"
    unit_prefix: k
    round: 3

The integration makes directly an energy devices out of a power device-

Could you show me how you did integrate it, I am trying to add it but my configuration keeps saying something is wrong :


# MyStrom Switch
switch:
  - platform: mystrom
    host: 172.16.1.7

  - platform: rest
    resource: http://172.16.1.7/report
    value_template: "{{ value_json.power | round(1) }}"
    name: "Power Mystrom"
    unit_of_measurement: W
    device_class: power

  - platform: integration
    source: sensor.power_mystrom
    name: "Energy Consumption"
    unit_prefix: k
    round: 3
Invalid config for [switch.rest]: [value_template] is an invalid option for [switch.rest]. Check: switch.rest->value_template. (See ?, line ?). 
Platform error switch.integration - No module named 'homeassistant.components.integration.switch'

I am really new so pardon me If it’s an easy fix for you.

@pixelwave same for yours I don’t understand how to fully integrate it, I keep getting errors

… with the recent HA releases the Mystrom integration seems broken. I do not currently get any readings from my sensor. -.-

There are bugs open to Add config flow for mystrom & Add power sensor for MyStrom. Both are waiting for a review by the same person. The power sensor one has been pending since July 2021, I suspect that means people just use workarounds.

For the MyStrom device, one solution could be to just flash it with Tasmota. For that, you have to open it up (needs a triangle screwdriver), solder a USB-TTL converter, and flash from your computer (it’s doable, but not trivial if you haven’t done it before).

To make it work with the REST API, I used the following in the configuration.yaml:

switch:
  - platform: mystrom
    name: mystrom_switch1
    host: 192.168.178.199
        
sensor:
  - platform: rest
    name: "mystrom_power1"
    resource: http://192.168.178.199/report
    method: GET
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    value_template: "{{ value_json.power }}"

  - platform: integration
    source: sensor.mystrom_power1
    name: "mystrom Energy Consumption"
    unit_prefix: k
    round: 3

Note that you have to place them in separate sections - switch & sensor. It checks every 30 seconds.

2 Likes

Hi,
for me it even works without the “platform”-part.
Why would I need the second part of the configuration?
Thanks for the clarification in advance!

This is needed to transform power (in W) into energy (kWh)…
You need to do an Integration

I have a variation of this.
While everyone is using the power attribute, I am using the Ws attribute from the API which gives an average of the power used / sec from the last request.

This is thus my config:

rest:
  - scan_interval: 10
    resource: http://192.168.0.170/report
    method: GET
    sensor:
      - name: "myStrom power"
        value_template: '{{ value_json.power}}'
        unit_of_measurement: 'W'
        device_class: power
        state_class: measurement
      - name: "myStrom energy"
        value_template: '{{ value_json.Ws}}'
        unit_of_measurement: 'W'
        state_class: measurement
        device_class: power
      - name: "myStrom relay"
        value_template: '{{ value_json.relay}}'
      - name: "myStrom temperature"
        value_template: '{{ value_json.temperature}}'
sensor:
  - platform: integration
    source: sensor.mystrom_energy
    name: myStrom energy consumption
    method: left
    round: 4

homeassistant:
  customize:
    sensor.mystrom_energy_consumption:
       unit_of_measurement: 'Wh'
       device_class: energy
2 Likes

that seems to work for now! thanks :slight_smile:

hello together

Have another question about the code
how do I insert the code I have a sensor.yaml and switch.yaml

Sorry am beginner thanks for your help

Sascha

Invalid config for [switch.template]: [sensors] is an invalid option for [switch.template]. Check: switch.template->sensors. (See ?, line ?).
Platform error switch.integration - No module named ‘homeassistant.components.integration.switch’

Hello everyone

The Integration doesn’t work for me? It doesn’t report any numbers. The Rest Call does work, there i see the power consumption, but then in the Energytab there is nothing reportet with the sensor. Any idea?

  - platform: rest
    name: "mspower_buro"
    resource: http://192.168.21.155/report
    method: GET
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    value_template: "{{ value_json.power }}"

  - platform: integration
    source: sensor.mspower_buro
    name: "Büro Verbrauch"
    unit_prefix: k
    round: 3

I have 7 sensors with different names. so the “ü” shouldnt be any problem

Hello,

I use my myStrom plugs for photovoltaic statistics.
What I would still like to use in hassio would be the total PV production per day from all plugs (I use 3).
Anyone an idea for a integration?

Perfect, thank you this is working!

Hi, thanks for the hint. Do you have an Idea how it should look like, when I want to integrate another mystrom switch. Especially the part with {{ value_json.power }}. Doesit need to be the same or do I need to rename it forevery switch?
Thanks Oliver

Hello,
I have a huge problem as I despair.

How can I create a sensor for the mystrom Wifi Switch that shows me the daily consumption.
At night it should be set to 0.
My sensor for the current production in W is called “sensor.mystrom_power”

I have created a counter helper that resets daily and then a Riemann sum integrator for the conversion into Wh, but it keeps counting on the dashboard…

thanks…

Hi softplus

Thanks for your code, works perfect with my myStrom switch.

How can I reset the couter of the energy consumption, so that it starts from “0 kwh” again?

Best Regards
Stephan

Good evening,
I have the same problem. I have 2 myStrom switches on 2 PV systems. I copied and pasted one in configuration.yaml and then changed the names, but that doesn’t work. Could someone please tell me what it should look like with 2 switches.
LG