Smarthome firmware pysmartnode

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Smarthome firmware pysmartnode

Post by kevinkk525 » Mon Oct 01, 2018 1:39 pm

I updated the framework to version 4.0.5 with many improvements over the last versions like:
* RAM usage optimizations, you can now use it on an esp8266 with activated filesystem (although not many components can be registered in this setup before you run out of RAM, more about this in the README)
* new modules (e.g. a modular heater system)
* updated many old modules
* more reliable mqtt connection
* unified access to machine.Pin and machine.ADC between esp8266 (even with nodeMCU pin names) and esp32_LoBo
* more examples and templates to explain how to add configuration and custom components
* multiple bugfixes and improvements especially in receiving a configuration over mqtt and loading components
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

arrowcircle
Posts: 2
Joined: Thu Nov 01, 2018 8:36 am

Re: Smarthome firmware pysmartnode

Post by arrowcircle » Thu Nov 01, 2018 9:31 am

Hi! Nice idea. Does your project support home assistance autodiscovery?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Smarthome firmware pysmartnode

Post by kevinkk525 » Thu Dec 20, 2018 2:59 pm

@arrowcircle: I somehow missed your message, sorry. It does not support home assistance autodiscovery but I always wanted to implement it. Maybe that will follow some day.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Smarthome firmware pysmartnode

Post by kevinkk525 » Thu Dec 20, 2018 3:01 pm

The framework is now updated to 4.0.6 but the bigger announcement is, that I had an error in my firmware build for the esp8266 resulting in 16kB less free RAM than I should have. Therefore I wrongly assumed that my framework is running on very low RAM but now I have ~7 active components and still 16kB of free RAM! This is enough for another ~6 sensors and many smaller components.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

rowanalex
Posts: 3
Joined: Thu Jan 03, 2019 6:07 am

Re: Smarthome firmware pysmartnode

Post by rowanalex » Thu Jan 03, 2019 6:11 am

This a very useful, thanks! What are your thoughts on adding HTTP support? Do you think the existing RAM on ESP8266 would be able to support it?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Smarthome firmware pysmartnode

Post by kevinkk525 » Thu Jan 03, 2019 6:57 am

What do you mean by HTTP support? Support for pysmartnode sending information to a HTTP server or getting information from pysmartnode using HTTP server on the esp?
As there are more than 10kB RAM left, I'd say that should be enough for a simple HTTP support. Never worked with one though.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Smarthome firmware pysmartnode

Post by kevinkk525 » Tue Apr 09, 2019 10:05 am

I pushed version 4.1.0 yesterday.

Key changes since my last update on the forum:

* Dropped official support of ESP32_Loboris_Fork because of lack of updates (no commit since 7 months). No code has been removed and modules are even updated to support it so could still mostly work on that fork, I just won't test it on that platform myself.
* Support for mainline ESP32 as all important bugs are finally fixed now
* [ecMeter] added module to measure EC with a simple cable
* [ds18] multiple bugfixes and improvements. Support for instanciating a single DS18 unit
* [ADC] updated to support ESP32 mainline. New interface and subclass logic to support custom ADC classes using external ADCs (like the Arduino). This makes using and implementing the unified ADC interface even easier.
* [Amux] improvements, supports Arduino ADCs & Pins -> possible to connect an AnalogMultiplexer to an Arduino and control remotely
* [ArduinoControl] Added library to control an Arduino by communication by 1-wire protocol
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Smarthome firmware pysmartnode now with Homeassistant mqtt discovery

Post by kevinkk525 » Sun Jul 07, 2019 6:47 am

Version 5.0.0 now finally supports Homeassistant mqtt discovery!
MQTT discovery: https://www.home-assistant.io/docs/mqtt/discovery/
Pysmartnode release: https://github.com/kevinkk525/pysmartno ... tag/v5.0.0
No more configuring each component inside HASS. It's enough to configure the components you want to use on the device (or the remote configuration server) and HASS will discover them automatically.

Also the unix port is now supported. Its use is limited as it doesn't have a GPIO interface but you can use system calls to execute (almost) anything you like. I use this to control a RF433MHz power switch.

A discovered device in homeassistant could look like this:
hass.JPG
hass.JPG (30.76 KiB) Viewed 5904 times


Also a few more changes:
* [MQTT] Integrated Homeassistant mqtt discovery feature
* [COMPONENTS] Completely changed the way components are integrated to support homeassistant mqtt discovery. Every component now has to use a common base component class. This is a major change breaking compatibility with previous pysmartnode/components versions and often component configurations.
* [COMPONENTS, MQTT] Mqtt subscriptions are not callback based anymore but component based. But within a component they are callback based.
* [COMPONENTS] Updated most components accordingly. Some topics and configurations have changed, check your configs! Not updated components were moved to _dev as they need more looking at.
* [Templates] Updated templates.
* [RAM] component is now part of a basic system component.
* [DS18] Component completely rewritten. It is now fully separated into a controller and a unit object. The controller has control over the onewire bus and reads all configured units. (Having other onewire devices on the same bus should be possible. No common onewire controller integrated at the moment). The DS18 unit object supports homeassistant discovery and therefore every DS18 unit connected to the controller has to be configured, unless auto-discovery is enabled on the controller, which will just create an object for each found sensor (this however makes using these in other components impossible and only serves to publish read temperatures).
* [UNIX] Added support for unix port of Micropython! (Most sensors won't be available as it doesn't have a gpio interface, working on an interface for the Pi). But you can execute system commands and e.g. use the rf433 raspberry-remote library
* [STATS] component now also publishes the wifi signal strength.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Smarthome firmware pysmartnode 6.0.0, major Component rework

Post by kevinkk525 » Thu Nov 07, 2019 11:31 am

Pysmartnode got a major update to version 6.0.0 introducing a sensor component offering a unified API and features, making developing and using sensors easy.
Also a new component: Climate (that's the homeassistant term, it's a mqtt controllable heating controller)

https://github.com/kevinkk525/pysmartno ... tag/v6.0.0

Changes:
Most noticeable changes:

Code: Select all

* [remoteSensors] use remote sensors as if they were locally connected
* [remoteSwitch] use a remote switch as if it was locally connected
* [COMPONENTS] extended API significantly, updated to new/changed MQTT features, added cleanup method
* [SENSOR COMPONENT] major base class for a unified sensor API and features to make usage and development easier
* [Sensors] updated all sensors to use the new SENSOR COMPONENT. Some sensors therefore experience breaking changes in configuration, default topics and behaviour.
* [DS18] rewritten for new sensor API
* [HEATER] removed deprecated component
* [CLIMATE] added new Climate component which is compatible to homeassistant MQTT Climate
* [STATS] Major update, publishing many device stats as hass json_attributes and RSSI as main value instead of "online/offline" which is now done directly in mqtt as availability topic. Published values: (last_boot, uptime, pysmartnode version, micropython firmware version, RAM free, RSSI, MQTT Downtime, MQTT Reconnects, Asyncio waitq used size)
* [MQTT] Improvements, Subscriptions done by mqtt not by components, Subscribing uses subscription chain and can be called non-blocking synchronously, added easy way to restore a device state from a state topic of a subscribed command_topic, prevention of uasyncio queue overflows when receiving too many messages

Configuring components is also very easy, with a few simple lines in "components.py" you can register a HTU21D temperature and humidity sensor and expose a set of pins on the device that are controllable over mqtt.
All components get automatically registered in home-assistant:

Code: Select all

from pysmartnode import config
from pysmartnode.components.machine.i2c import I2C
from pysmartnode.components.sensors.htu21d import HTU21D
from pysmartnode.components.machine.easyGPIO import GPIO
i2c = I2C(SCL="D6", SDA="D5")
config.addComponent("i2c", i2c)
htu = HTU21D(i2c, precision_temp=2, precision_humid=1, temp_offset=-2.0, humid_offset=10.0)
config.addComponent("htu", htu)
gpio = GPIO(discover_pins=["D0", "D1", "D2"])
config.addComponent("gpio", gpio)

Creating new sensors is easy:

Code: Select all

class MySensor(ComponentSensor):
    def __init__(self, **kwargs):
        super().__init__(**kwargs) # shorted to **kwargs to not distract

        self._addSensorType(SENSOR_TEMPERATURE, precision_temp, temp_offset, _VAL_T_TEMPERATURE,
                            "°C", friendly_name_temp)
        self._addSensorType(SENSOR_HUMIDITY, precision_humid, humid_offset, _VAL_T_HUMIDITY, "%",
                            friendly_name_humid)

        ##############################
        # create sensor object
        self.sensor = Sensor(i2c=i2c) 
        ##############################
        gc.collect()

    async def _read(self):
        t = await self.sensor.temperature()
        h = await self.sensor.humidity()
        await self._setValue(SENSOR_TEMPERATURE, t)
        await self._setValue(SENSOR_HUMIDITY, h)

Creating new Switch components is easy too:

Code: Select all

class Switch(ComponentSwitch):
    def __init__(self, mqtt_topic=None, friendly_name=None, discover=True):
        super().__init__(**kwargs) # shorted to **kwargs to not distract

    #####################
    # Change these methods according to your device.
    #####################
    async def _on(self):
        """Turn device on."""
        return True  # return True when turning device on was successful.

    async def _off(self):
        """Turn device off. """
        return True  # return True when turning device off was successful.
    #####################


The framework takes care of keeping connected, publishing state changes to mqtt, handling mqtt requests as well as reading the sensors and publishing sensor readings.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

eskhool
Posts: 1
Joined: Wed Feb 24, 2021 4:44 pm

Re: Smarthome firmware pysmartnode

Post by eskhool » Wed Feb 24, 2021 4:53 pm

Trying to weigh pysmartnode vs esphome for my personal home automation project. Any you share your thoughts on the pros and cons of both?

Thanks

Post Reply