Coder Social home page Coder Social logo

hass-bbc-envirobit's Introduction

HASS-BBC-envirobit

Stream button presses and BME280 sensor readings over the serial from the BBC micropython envirobit to Home-Assistant.

BBC-envirobit setup

main.py should be flashed to tbe BBC microbit. On pressing the A or B buttons the display will scroll the pressed button. The buttons are displayed as a binary sensor in Home-Assistant and can be used to trigger automations. Data from the BME (temperature, pressure, humidity, but not altitude as these values were meaningless in my testing) are publihsed to Home-Assistant every second (the sleep time is a variable sleep_sec which you can optimise). The number of decimal places that data is reported to is 1dp by default, but can be varied with the rounding_digits variable. Plug the microbit into the USB port on your Home-Assistant computer.

Home-Assistant Usage with HASSOS

On HASSOS, the microbit is on /dev/ttyACM0

We can now configure Home-Assistant to display the data feed. I add to my Home-Assistant config:

sensor:
  - platform: serial
    serial_port: /dev/ttyACM0
    baudrate: 115200

We then use template sensors to break out the data fields. Under sensor:

  - platform: template
    sensors:
      temperature:
        friendly_name: Temperature_microbit
        unit_of_measurement: "°C"
        value_template: "{{ states.sensor.serial_sensor.attributes.T }}"

The final config for all sensors is:

sensor:
  - platform: serial
    serial_port: /dev/ttyACM0
    baudrate: 115200
  - platform: template
    sensors:
      temperature:
        friendly_name: Temperature_microbit
        unit_of_measurement: "°C"
        value_template: "{{ states.sensor.serial_sensor.attributes.T }}"
      pressure:
        friendly_name: Pressure_microbit
        unit_of_measurement: "hPa"
        value_template: "{{ states.sensor.serial_sensor.attributes.P }}"
      humidity:
        friendly_name: Humidity_microbit
        unit_of_measurement: "%"
        value_template: "{{ states.sensor.serial_sensor.attributes.H }}"

binary_sensor:
  - platform: template
    sensors:
      button_a:
        friendly_name: Button_A_microbit
        value_template: "{{ states.sensor.serial_sensor.attributes.ba |float > 0}}"
      button_b:
        friendly_name: Button_B_microbit
        value_template: "{{ states.sensor.serial_sensor.attributes.bb |float > 0}}"

history_graph:
  microbit:
    entities:
      - sensor.temperature
      - sensor.pressure
      - sensor.humidity

Mac usage

To check which port the microbit is on I run (on Mac/unix):

ls /dev/cu.*

In my case the microbit is connected on /dev/cu.usbmodem14342. I now use screen to check the data transmitted over the serial. In the terminal I launch screen with:

screen /dev/cu.usbmodem14342 115200

Note that if you get any funny errors when connecting, check that there is not already a screen session open using the Activity monitor, and kill any existing processes. You can also kill a screen session using ctrl + a + k.

Notes

I discovered that you can't mix numerical and text data in the payload string. If you try Home-Assistant displays no data.

hass-bbc-envirobit's People

Contributors

robmarkcole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hass-bbc-envirobit's Issues

Limit data publish rate

Currently publish data every 1 second interval. This is excessing and quickly filling the HA database. On the other hand we want instant updates when the buttons are pressed. Implement logic to handle these cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.