Mysensors OTA firmware updates?

Does the mysensors platform support OTA firmware updates?

There’s support in pymysensors, which is the library home assistant uses to interface with mysensors gateways, for OTA updates. But this is not yet made available in home assistant. I have started on a branch to add a service for this. You can find that in my github fork of home assistant. Anyone is welcome to continue on this or start fresh and make a PR.

What is the status of your ota branch for Home Assistant? I would really like to be able to shoot new firmware to the nodes without restarting Home Assistant all the time :wink:

It should work, but my gateway that I’ve used for testing isn’t stable enough to allow testing uploading the whole firmware. It reboots during the process. If someone can test the branch and confirm it works by uploading a complete sketch to a node, I can make a PR and get the branch released.

Edit:
I forgot, I need to release an update to pymysensors with a fix too. After that is done, testing should be ok, as I said above.

1 Like

Good stuff. Please let me know when your fix is available and I’ll pull your changes and try to update a node. Thanks!

1 Like

Ok, I’ve released pymysensors 0.12.0 and rebased and upgraded my home assistant ota branch to use pymysensors 0.12.0. See:

Edit:
Ok, I forgot I need to change the call for registering the service. The signature for that has changed in the core. I’ll push an update later tonight hopefully.

I’ve fixed a bug in pymysensors and released 0.12.1. My ota branch is updated and should be ready for testing now.

Yes! :smile: The OTA service works just as advertised! Thank you!!!
Just a few comments. The service call to mysensors.update_firmware

{
 "entity_id": "sensor.movie_screen_3_2",
 "firmware_type": 1,
 "firmware_version": 1,
 "firmware_path":"/home/homeassistant/.homeassistant/mysensors/moviescreen.hex"
}

Would it be feasible to shorten the firmware parameter names by removing “firmware_”. It is little bit too verbose?

The update procedure does not trigger immediately, but waits for a SET request from the node before sending the reboot command. I would really like to have the possibility to force an update by shooting the reboot command when the service is called. Could be added as a “force” parameter to the service call? Like urgently pushing new firmware to nodes.

In non-forced “normal” mode maybe it’s good to wait for any life sign from the node, not only SET requests. I have a few battery powered nodes that sometimes only sends heartbeat every now and then. They might have to wait for a very long time before receiving new firmware. Since they maybe only sends SET requests once a day.

Thoughts?

Thanks for testing and for the feedback. I’ll try to make the requested changes.

Might have jumped the gun a little bit. It seems that the call to update_firmware never completes.

all_devices = [
            get_mysensors_devices(hass, domain) for domain in domains]

Never gets populated with any devices.

            gateways[gateway_id].update_fw(
                list(set(nodes)), fw_type, fw_version, fw_path)

Variable gateways never gets initialized?

Also there seems to be a problem with setup_mysensors_platform()
Running 0.62 and Python 3.6.3:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 189, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/sensor/mysensors.py", line 15, in setup_platform
    hass, DOMAIN, discovery_info, MySensorsSensor, add_devices=add_devices)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/mysensors.py", line 603, in setup_mysensors_platform
    devices[dev_id] = device_class_copy(*args_copy)
TypeError: list indices must be integers or slices, not tuple

Are you using my branch directly? It should be version 0.61.0.dev0.

No. I only pulled the diff.

The stack trace is weird since devices should be a dict. Also the line number doesn’t match with my branch. I would try my branch directly.

Nevermind the stacktrace and line numbers, I’ve made other changes. I cherry-picked your OTA commit. But the fact still remains. all_devices never get populated because:

def get_mysensors_devices(hass, domain):
    """Return mysensors devices for a platform."""
    if MYSENSORS_PLATFORM_DEVICES.format(domain) not in hass.data:
        hass.data[MYSENSORS_PLATFORM_DEVICES.format(domain)] = {}
    return hass.data[MYSENSORS_PLATFORM_DEVICES.format(domain)]

hass.data[MYSENSORS_PLATFORM_DEVICES] is never populated.

I’m no Python developer but occasionally get tasked with Python code at work, I usually prefer plain old C :blush:

I can’t troubleshoot for you if I don’t know what source you’re using. Please test my branch directly. Main functionality worked last time I tested.

No need for troubleshooting, couldn’t get the OTA branch working, worked around it so I’m good. Since my Python skills are not on par with justifying a PR I humbly asked if there might be an issue with the OTA branch. Just pointed out where in the code it seemed to fail in my setup. Maybe I’m blind but I failed to find out where hass.data[MYSENSORS_PLATFORM_DEVICES] is appended with data.

Hi there

I tested the OTA service (commit 803f965) and found the same problem as @Redferne. I figured out the cause, and with the change in this PR, have been able to upload a firmware successfully. Not 100% sure if this is the most error-proof way of implementing the solution, so if you would check it critically, I’d be grateful.

Thanks for the work, hope this will make it possible to add the OTA functionality to HA!

pragtich

2 Likes

Hi there!
Please anybody can help me to make able OTA on current version of MySensors component?