Adding support for Smappee

Hi doune,

Great work!
I can get your examples to work. Var0 receives the login auth. ok, but var1 is empty.


var0=$(curl -silent -H “Content-Type: application/json” -X POST -d “admin” http://192.168.1.32/gateway/apipublic/logon)
var1=$(curl -silent http://192.168.1.32/gateway/apipublic/reportInstantaneousValues | awk ‘{split($0, a, “”); print a[5]}’ | awk ‘{split($0, b, “,”); print b[2]}’ | awk ‘{split($0, c, “=”); print c[2]}’ | awk ‘{split($0, d, " "); print d[1]}’)
echo $var1

Also: controlling the plugs dissent seem to work!? The response from the curl is:

HTTP ERROR 405

Problem accessing /apipublic/commandControlPublic. Reason:

    HTTP method POST is not supported by this URL

Powered by Jetty://

Any tips?
/Tonkin

Sorry!! I Cant get your examples to work

Hi Giel,

The Pandas package is only used for a single method in smappy (get_consumption_dataframe), so as long as you are not using that method you could perfectly omit pandas.

I have updated the package to exclude pandas as a requirement and top level import, so pip install smappy should now work without problems on a raspberry pi.

Also, installing Pandas through pip is not recommended on Linux systems, so you should use sudo apt-get install python-pandas if you plan on using the get_consumption_dataframe method.

Have you tried to update the IP adress in the script ?

Mine is 192.168.1.32 but yours ?

Hi

I’d like to share my findings on this integration.
The provided script doesn’t work for me, don’t know why but the output is somewhat different from the @doune ones. Also auth is not needed (var0).

These are the scripts I’m using just modifying the awk part:

Watt

#!/bin/bash

var1=$(curl -s http://192.168.1.100/gateway/apipublic/reportInstantaneousValues | awk '{split($0, a, " "); print a[6]}'|awk '{split($0, c, "="); print c[2]}')
echo $var1

Ampere

#!/bin/bash

var1=$(curl -s http://192.168.1.100/gateway/apipublic/reportInstantaneousValues | awk '{split($0, a, " "); print a[4]}'|awk '{split($0, c, "="); print c[2]}')
echo $var1

Cos fi

#!/bin/bash

var1=$(curl -s http://192.168.1.100/gateway/apipublic/reportInstantaneousValues | awk '{split($0, a, " "); print a[12]}'|awk '{split($0, c, "="); print c[2]}'|awk '{split($0, c, ","); print c[1]}http')
echo $var1

Following an example of the JSON my smappee is answering.

We could try and merge this topic with: Smappee custom component and get a proper component into HA

Sure! the Smappee component is quite cooler than these bunch of scripts.

1 Like

thanks for the “bunch of scripts”… #makemehappy

I’m sorry @doune, didn’t want to offend you or your useful work that let me succesfully integrate smappee in my home-assistant.
I just wanted to highlight having a native component is more elegant than external script dependancies.

Peace :peace_symbol:

Hi guys,

I just buyed a Smappee Energy and asked for API access.

Customer service told me that API access isn’t free anymore and suggest me to use MQTT.

They send me this document.

https://support.smappee.com/attachments/token/Fxcc6mPCUyHrTBtaYw41yEKW6/?name=Smappee+local+MQTT+topics+-20-09-2018.pdf

I think someone needs to update component page (I’m a total noob), no?

I got today new MQTT information from Smapee but this leads for me in more questions then answers. I am not really a MQTT specialist but as I know from other MQTT projects, it is needed that the MQTT topic publisher (Smappee) knows the Brocker Name (IP Adress) and connect with a user name/passwort to transmit the information to the brocker. I use the internal MQTT broker of hassio. This is not mentioned in the documentation. How I can conncect then the Samppee MQTT to my internal broker? Any idea? It would be great if we have a “custom card” specialst here how could build a Sampee custom card with this new parts of information.
(Documentation enclosed)
image

After some days of hard work I was able to read most interesting values via mqtt from my new Smappee Energy. With some automation and calculation KWh and price for today, month and year is done. Also the Smapee switch can be toggled. All works without the API.

2 Likes

Can you share your code?

Of course … but lets do it step by step for better overview.
Step 1 - Setup Mqtt broker (Mosquitto)
You should start (if currently not already done) setup the Home Assistant (Hass.io) Mosquitto Add-On as the Mqtt broker. The build in Mqtt component will not work with Smappee Energy properly. Steps: Install the add-on, configure the add-on, create an mqtt user in HA with username/password, configure the mqtt component in “Integration” with same username/password. Afterwards visit the mqtt testing documentation (https://www.home-assistant.io/docs/mqtt/testing/) and test the installation. The logfile of the mosquitto add-on will show you if all is correct done. Please come back if this first step is successful done. You should also install a Mqtt “observer” like Mqtt.fx on a PC (e.g. Windows). This is very helpful to check the communication between HA Mqtt brocker and the clients. It will tell you later also the uuid and node-id of your Smappee components. In Mqtt.fx setup a new connection to HA (you need the IP address, mqtt username and password). Now you can subscribe with a “#” all topic which Mosquitto will receive from the Mqtt clients. Later we can do it more specific for the different Smappee topics.

1 Like

I have Smappee already working with mqtt, but I don’t find ‘Verbrauch Monat’, ‘Verbrauch Jahr’ and ‘Kosten …’

Ok, that sound good. If mqtt with Smappee already running most work is done. The values for consumption and cost are calculated values and not delivered from Smappee. I have the total power value via mqtt. This value will be updated every second. What I do is to sum the total power in a variable as “consumtion in Ws”. In a second variable I divide the ws variable / 3600000 = Kwh ->today. With automation I sum with a trigger at time 00:00:00 KWh_today in variable KWh_month and reset the variable ws_today. In a second automation the trigger is time 00:00:00 with condition day_of_month=1 and reset the KWh_month variable. Same is done for cost calculation. Cost_today is kwh_today *0.25€ (price per KWh) . Month and year calculation same as before. To get a variable option in Hass.io I installed a custom component called “hass-variable” (Link: https://github.com/rogro82/hass-variables) I hope that explained how I did it.

1 Like

That’s why I was unable to set power consumption properly!

I think I have understand your argumentation but I’m not as pro to create such variable on HA.

@Obicom can you please help me setting up this?

In order to help others and also to get help :slight_smile:

This is my setup:
After having configured smappee to send the information to the mqtt broker (device web interface) and looked for the uuid using a tool like MQTTSpy, I’ve configured the following sensors:

- platform: mqtt
  state_topic: "servicelocation/<UUID>/realtime"
  name: "Smappee Power"
  unit_of_measurement: "W"
  value_template: "{{ value_json.totalPower }}"
- platform: mqtt
  state_topic: "servicelocation/<UUID>/realtime"
  name: "Smappee Voltage"
  unit_of_measurement: "V"
  value_template: "{{ value_json.voltages.0.voltage }}"
- platform: mqtt
  state_topic: "servicelocation/<UUID>/realtime"
  name: "Smappee Intensity"
  unit_of_measurement: "A"
  value_template: "{{ value_json.channelPowers.0.current/10 }}"
- platform: mqtt
  state_topic: "servicelocation/<UUID>/aggregated"
  name: "Smappee Cosφ"
  unit_of_measurement: "%"
  value_template: "{{ value_json.intervalDatas.0.channelIntervalDatas.0.averagePowerfactor }}"

Cosφ values are updated every 5 minutes while the others every second, please consider the possible load on your setup.

To configure the Plug I’ve setup a mqtt switch like the following:

switch:
  - platform: mqtt
    icon: mdi:mdi-power-socket-eu
    name: "Lavatrice"
    state_topic: "servicelocation/<UUID>/plug/1/state"
    command_topic: "servicelocation/<UUID>/plug/1/setstate"
    payload_on: '{"value":"ON","since":""}'
    payload_off: '{"value":"OFF","since":""}'
    state_on: "ON"
    state_off: "OFF"
    value_template: "{{ value_json.value }}"
    optimistic: false
    retain: true

Everything is working fine, only issue is for the switch command where in the since value I need to insert “The timestamp is the number of milliseconds that have passed since Jan 1st, 1970 (UTC).” that I have also in the state topic but I don’t know how to calculate/extract the value.

Without this value I can only read the switch state and not change it.
I’m not an expert with Jinja so any help here is welcome.

2 Likes

Can you explain me please what Cosφ measures?