SigFox component

Hi @robmarkcole, I’ll need time, I’m moving so all my stuff are in boxes. I hope to continue in some days.

Thanks in advance for your help.

1 Like

Hi @lhanneus

I’ve the same problem.

I’m using an Arduino MKRFOX1200 as a meteorological station sending temperature, pressure, humid and altitude using a “custom grammar” simillar to yours, and for example my payload is "0033332941889f1113beac00 "

My Home Assistant error is:

payload = bytes.fromhex(data[‘data’]).decode(‘utf-8’)
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x84 in position 5: invalid start byte

@robmarkcole Any help?

HI @Pharizna the component doesn’t support custom encoding, as I didn’t even know about custom encoding when writing the component. I suggest you use regular encoding and use a HA template to decode the payload, but I haven’t tried this myself

Thank you @robmarkcole … but how can I send data about 5 sensors in just only message using regular encoding?

Would it be possible to read in HA just the “ascii” message?
0033332941889f1113beac00

Would it be enough removing the decode section of your command?
payload = bytes.fromhex(data[‘data’]).decode(‘utf-8’) -> payload = bytes.fromhex(data[‘data’])

Could I use a template to read bytes?

I’ve not tried myself but expect its possible, if you get it working could you submit a PR?
The sigfox component is an MVP for a project I’m working on (slowly!)

Hi @lhanneus

Have you solve the decoding of your ‘custom grammar’?

I can read now the payload long string from Sigfox.

I’m using this ‘custom grammar’ and I don’t know how to extract, for example, the ‘5138’ substring in order to convert it to “14417” in decimal format :slight_smile:

Thank in advance you for your help to write the right template

Solved it myself :slight_smile:

  - platform: template
    sensors:
      sigfox_temp:
        friendly_name: Temperatura
        value_template: '{% set temp= states("sensor.mkrfox_18ba5a")[6:9] + states("sensor.mkrfox_18ba5a")[3:6] %}
                         {% set valor=temp|int(value,16)/32767*55-5 %}
                         {{"%0.1f"| format(valor|float)}}'
        icon_template: mdi:thermometer
        unit_of_measurement: "ºC"
1 Like

I’m curious, I see that @Pharizna use MKRFOX Arduino, what are other setup ?

I want to use Sigfox with presence detection sensor + DHT22 and I wonder if there is another cheaper way than Arduino Fox.

I’m using a Pycom Lopy4

1 Like

Hi, @Pharizna and @lhanneus i face the same problem as you i believe.
I have a Arduino mkrfox that is sending custom data (in callback also to Thingspeak).
I have created an API login for this user/device.
This is the output from HA log;

sigfox: Error on device update!
Traceback (most recent call last):

  • File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 292, in _async_add_entity*
  • await entity.async_device_update(warning=False)*
  • File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 450, in async_device_update*
  • await self.hass.async_add_executor_job(self.update)*
  • File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run*
  • result = self.fn(*self.args, *self.kwargs)
  • File “/usr/src/homeassistant/homeassistant/components/sigfox/sensor.py”, line 144, in update*
  • self._message_data = self.get_last_message()*
  • File “/usr/src/homeassistant/homeassistant/components/sigfox/sensor.py”, line 129, in get_last_message*
  • payload = bytes.fromhex(data[“data”]).decode(“utf-8”)*
    UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xc2 in position 1: invalid continuation byte

Is it possible to point out where or what code was altererd to get it working?
Thanks

Had the same error.
You should protect the decode operation
payload = bytes.fromhex(data[‘data’]).decode(‘utf-8’)
by
try:
payload = bytes.fromhex(data[‘data’]).decode(‘utf-8’)
except UnicodeDecodeError:
# just take it as it is it can be raw binary data
payload = data[‘data’]

I may submit a patch for that.

Thank you for the reply, where is the code located that has to be altered?
I assume it is the sensor.py file but cannot find it in the home assitant configurator .

Yes, it is in sensor.py, line 128 in version 0.102.3
I’ll submit a patch in a few minutes.

Patch submitted.

@flebourse thanks.

ps: where can i find thr sensor.py file in the HA maps?

Depends on your installation.
Mine:
/root/homeassistant/lib/python3.7/site-packages/homeassistant/components/sigfox/sensor.py

If you do the edit, copy all the files in the sigfox directory to your .homeassistant/custom_components/sigdox
Create the subdirs as appropriate.

and edit the copy.
I’ts late. mouse faster than brain.

@flebourse Thanks for the info.

I found the map usr/local/lib/python3.7/site-packages
Unfortunately i can not find a map inthere called components/sigfox/sensor.py, very weird. It has to be somewhere.
I run hassio on Raspberry Pi

I have now made a custom_components folder in my config. Will check tommorow if the edited sigfox file here works.

The custom_components/sigfox is the cleanest way.
for the original:
find / -name sigfox -print
should give you the location.