Adding support for Smappee

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?

It’s the Power Factor, it’s not useful in home distribution since utility companies usually only charge low power factor for commercial customers.

It’s a measure for the efficiency of the load that causes extra effort for the distribution.

More details here:

Thank you :grinning:

About the MQTT switch to manage the plugs, I asked also in this topic

using

payload_on: '{"value":"ON","since":"{{ as_timestamp(now())|int }}"}'

but seems that payload_on does not accept templates. :frowning:

MQTT and Smappee is working great for me, I’ve now got a graphic that updates by the second showing where power for the house is coming from.

Hi
Could you please help how to get the UUID from MQTTspy

Sorry for the late answer:

Subscribe to # topic and look for servicelocation/ topic in the received messages summary, the string after / is your UUID

hi all,
i can’t find an answer to my question. Someone could help me to integrate smapee without api cloud ??

Hello… You have at least two solutions:

  • use MQTT (I am using mosquitto), Smappee send a record to MQTT with all the data every second… !!! if you record the sensors, be careful about the size of the history database… !!! To configure MQTT on Smappee, you have to connect to : http://“your smappee LAN IP”/smappee.html . Login with “admin” as password. Go to “advanced” tab, check the advanced box, than you have the fields to configure MQTT on your smappee. Type location of the MQTT broker on the lan + port, username and password to connect on MQTT broker (I use on logonid per device connected to MQTT)… Save and restart Smappee. Than you can find on MQTT the records sent by Smappee: “servicelocation/Smappee UUID/realtime”… You can replace “Smappee UUID” by “#” to get the uuid used by your smappee… than you define a sensor in HA like this for example:
- platform: mqtt
  state_topic: "servicelocation/<your UUID>/realtime"
  name: "Smappee Solar c"
  unit_of_measurement: "W"
  value_template: "{{value_json.channelPowers[0].power}}"

  • second solution: use a python script (in the following I am reading the power used on phase 2). You run it on regular basis (every 10 to 20 seconds for example):
import smappy

ls = smappy.LocalSmappee(ip='<smappee LAN ip>')
ls.logon(password='admin')
smappeeData = ls.load_instantaneous()
solarPowerInWatts = 0
for itemDict in smappeeData:
    key = itemDict.get('key')
    if key in ['phase2ActivePower']:
        value = itemDict.get('value')
        phasePowerInWatts = int(float(value) / 1000)
        solarPowerInWatts += phasePowerInWatts
print(solarPowerInWatts)

Smappy module is installed with the command: pip install smappy
I am running HA in a virtual environment (Raspberry pi 4 + Python 3.7 and HA 0.102.2)

I moved recently from solution 2 (script) to MQTT which is more accurate but generate more data…

Let me know if you need more info… Have fun !

Hi,

with the second solution you can get more info from the gateway? As you know one of the best feature is device footprint recognition that is now only availabe with a non-free api access.

So I was wondering if somehow we can rehave possess of our data.

Thank you in advance

The data received is the same, the first method is that Smappee is pushing the data to MQTT every second, the second you pull the data from Smappee at the frequency you want… No additional info about the device recognition as far as Iknow…