Adding support for Smappee

@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…

Thank you for your feedback

Only to give another option to interested people.
With the information of this thread (thanks!) I have added the integration in Node RED. The benefit over do it like native sensors, is that I added a “smoothing” element that takes 10 values and calculates the medium value and outputs only one.
In this way, we receive the same values (one each second) but we reduce a little the overhead modifying the sensor in HA only one each 10 seconds, reducing the history of this sensor, the refreshing, etc.

1 Like

Would you like to share your Node RED flow?
Sounds very interesting!

1 Like

@gizzmo sorry, I didn’t see your reply, I need to change my notifications I think…

Here you have, if it can help someone:

[{"id":"7c133d97.5d12e4","type":"mqtt in","z":"6b0187c1.7dbdd8","name":"Smappe realtime","topic":"servicelocation/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/realtime","qos":"0","datatype":"json","broker":"8983b10f.7332a","x":120,"y":240,"wires":[["add3a5ea.052648","49b36003.5067","b5c928fd.598aa8","b66ce01a.a81f1"]]},{"id":"add3a5ea.052648","type":"smooth","z":"6b0187c1.7dbdd8","name":"Media consumo","property":"payload.totalPower","action":"mean","count":"10","round":"0","mult":"multi","reduce":true,"x":500,"y":160,"wires":[["f95a147f.012cc8"]]},{"id":"49b36003.5067","type":"smooth","z":"6b0187c1.7dbdd8","name":"Media intensidad","property":"payload.channelPowers.0.current","action":"mean","count":"10","round":"0","mult":"single","reduce":true,"x":510,"y":280,"wires":[["41579ee8.6f88f"]]},{"id":"b5c928fd.598aa8","type":"smooth","z":"6b0187c1.7dbdd8","name":"Media voltaje","property":"payload.voltages.0.voltage","action":"mean","count":"10","round":"0","mult":"single","reduce":true,"x":490,"y":220,"wires":[["7c865606.f49248"]]},{"id":"7c865606.f49248","type":"ha-entity","z":"6b0187c1.7dbdd8","name":"Smappee Voltaje","server":"e03e6d0f.b2759","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Smappee Voltaje"},{"property":"device_class","value":"power"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"V"}],"state":"payload.voltages.0.voltage","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":990,"y":220,"wires":[[]]},{"id":"41579ee8.6f88f","type":"change","z":"6b0187c1.7dbdd8","name":"Ajustar unidades","rules":[{"t":"set","p":"payload.channelPowers.0.current","pt":"msg","to":"$round(payload.channelPowers[0].current / 10, 1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":280,"wires":[["dacd40b.f38f6c"]]},{"id":"dacd40b.f38f6c","type":"ha-entity","z":"6b0187c1.7dbdd8","name":"Smappee Intensidad","server":"e03e6d0f.b2759","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Smappee Intensidad"},{"property":"device_class","value":"power"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"A"}],"state":"payload.channelPowers.0.current","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1000,"y":280,"wires":[[]]},{"id":"f95a147f.012cc8","type":"ha-entity","z":"6b0187c1.7dbdd8","name":"Smappee Consumo","server":"e03e6d0f.b2759","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Smappee Consumo"},{"property":"device_class","value":"power"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"W"}],"state":"payload.totalPower","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1000,"y":160,"wires":[[]]},{"id":"6dfc5cd8.b45b34","type":"mqtt in","z":"6b0187c1.7dbdd8","name":"Smappe aggregated","topic":"servicelocation/XXXXXXXXXXXXXXXXXXXXXXXXXXXXX/aggregated","qos":"0","datatype":"json","broker":"8983b10f.7332a","x":130,"y":460,"wires":[["9baf4022.044a2","931295af.f1d4e8"]]},{"id":"9baf4022.044a2","type":"change","z":"6b0187c1.7dbdd8","name":"Ajustar unidades","rules":[{"t":"set","p":"payload.intervalDatas.0.alwaysOn","pt":"msg","to":"$round(payload.intervalDatas[0].alwaysOn / 1000, 1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":500,"wires":[["168a717c.0e814f"]]},{"id":"931295af.f1d4e8","type":"change","z":"6b0187c1.7dbdd8","name":"Ajustar unidades","rules":[{"t":"set","p":"payload.intervalDatas.0.channelIntervalDatas.0.averageImportRMSActivePower","pt":"msg","to":"$round(payload.intervalDatas[0].channelIntervalDatas[0].averageImportRMSActivePower / 1000, 1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":440,"wires":[["17ffae0c.277092"]]},{"id":"17ffae0c.277092","type":"ha-entity","z":"6b0187c1.7dbdd8","name":"Smappee Consumo (5m)","server":"e03e6d0f.b2759","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Smappee Consumo (5m)"},{"property":"device_class","value":"power"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"W"}],"state":"payload.intervalDatas.0.channelIntervalDatas.0.averageImportRMSActivePower","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1010,"y":440,"wires":[[]]},{"id":"168a717c.0e814f","type":"ha-entity","z":"6b0187c1.7dbdd8","name":"Siempre encendido","server":"e03e6d0f.b2759","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Smappee Siempre Encendido"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"W"}],"state":"payload.intervalDatas.0.alwaysOn","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":990,"y":500,"wires":[[]]},{"id":"c1445d6e.de28e","type":"config","z":"6b0187c1.7dbdd8","name":"Constantes y propiedades","properties":[{"p":"POTENCIA_CONTRATADA","pt":"flow","to":"3450","tot":"num"},{"p":"SEGUNDOS_INTERVALO","pt":"flow","to":"10","tot":"num"}],"active":true,"x":160,"y":60,"wires":[]},{"id":"b66ce01a.a81f1","type":"delay","z":"6b0187c1.7dbdd8","name":"Limitar cada 10 seg","pauseType":"rate","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":510,"y":340,"wires":[["41c20caa.effbd4"]]},{"id":"41c20caa.effbd4","type":"change","z":"6b0187c1.7dbdd8","name":"Ajustar unidades","rules":[{"t":"set","p":"payload.totalImportEnergy","pt":"msg","to":"$round(payload.totalImportEnergy *  0.0000002778, 2)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":340,"wires":[["f096b42d.cf9dd8"]]},{"id":"f096b42d.cf9dd8","type":"ha-entity","z":"6b0187c1.7dbdd8","name":"Smappee Energía Total","server":"e03e6d0f.b2759","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Smappee Energía Total"},{"property":"device_class","value":"power"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"kWh"}],"state":"payload.totalImportEnergy","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1010,"y":340,"wires":[[]]},{"id":"8983b10f.7332a","type":"mqtt-broker","z":"","name":"Home Assistant MQTT","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"e03e6d0f.b2759","type":"server","z":"","name":"Home Assistant","addon":true}]

The texts are in Spanish:

2 Likes

Anyone wants to sell the smappee solar? :wink:

Great work! I was looking for a way to do this but couldn’t come up with one. You might convince me to finally install node-red. Just a pity their MQTT api sucks so much.

You can do the same with Home Assistant filters too: https://www.home-assistant.io/integrations/filter/

And disable the recorder for the original entity.