A New Output to the LEDs on the SenseHat

I’m in the process of setting up 1 of 8 Mycodo Systems, each system includes:
6 to 8 temp ds18b20 sensors
2 humidity sensors
3 light sensors (uva, uvb and visible light)
2 8 relay switch for (2) heat lamps, (2) 4’ led lights, vent fan, fog, mist sprayer, (2) water pumps, ceramic heater, 4 uva/uvb lights, and a 300 watt power supply.
2 to 3 capacitance moisture sensors
1 distance sensor for the fog sensor
1 SenseHat
1 OLED display
2 microphones
camera

With 8 systems, I need something that I can glance at as I’m taking care of them, instead of jumping on the computer and check every system. I’d like to use the Led’s on the SenseHat as a visual status indicator; blue - low, green - ok, and red - too high.

Please advise

The easiest way to manipulate LEDs based on measurements is to use a Conditional Controller from the Function page. Every Period, your Conditional Controller can compare the latest measurement to a set range you specify, then change the LEDs accordingly, based on what color you want to display for each range the measurement falls within.

Kyle

thanks for the info… that just what I’m looking to do. I’ve been trying to create a custom output and have basically gotten nowhere other than crashing the system twice so bad that I had to reload Mycodo from scratch twice… I had been using restore but after a while that didn’t help.

1 Like

I spent most of yesterday trying to get a measurement from one DS1B20 and activates an led on the senseHAT. Based on the measurement value sets the color of the led. But, I just cannot get the following to work. Could someone help me out??

It appears that the issue is with the Execute Command: Shell : Execute a Linux shell command.
each Command is:

Command - sense.set_pixel(0, 1, 0,0,xxx)
User - mycodo

Measurement (Single, Last) : self.condition("{95cecc0d}") returns the last value found

self.run_action("{578cf025}") will execute = sense.set_pixel(0, 1, 0,0,0)
self.run_action("{0411875f}") will execute = sense.set_pixel(0, 1, 0,0,255)
self.run_action("{4842a316}") will execute = sense.set_pixel(0, 1, 0,255,0)
self.run_action("{7a3f837f}") will execute = sense.set_pixel(0, 1, 255,0,0)

The Conditional Statement CODE is:

# Lights up an LED based on the current sensor reading

from sense_hat import SenseHat
sense = SenseHat()

sense.clear()

measurement = self.condition("{95cecc0d}")
self.logger.info("DS18B20-1 Measured value is {val}".format(val=measurement))

if measurement is None:  # No Measurement Received
    self.message += "DS18B20-1 No Measurement Received!\n"
    self.run_action("{578cf025}")  # Set LED - sense.set_pixel(0, 1, 0,0,0)
    self.logger.info("No Measurement Received {val}".format(val=measurement))

elif measurement < 80:  # If the measurement is less than 80
    self.message += "DS18B20-1 Measured value is too Low! Measurement is {meas}\n".format(meas=measurement)
    self.run_action("{0411875f}")  # Set LED - sense.set_pixel(0, 1, 0,0,255)
    self.logger.info("DS18B20-1 Measured value < 80 {val}".format(val=measurement))

elif 80 < measurement < 100:  # measurement is greater than 80 and less than 100
    self.message += "DS18B20-1 Measured value is in the ZONE! Measurement is {meas}\n".format(meas=measurement)
    self.run_action("{4842a316}")  # Set LED - sense.set_pixel(0, 1, 0,255,0)
    self.logger.info("DS18B20-1 Measured value is > 80 and < 100 {val}".format(val=measurement))

else:    # measurement > 100:  # Else If the measurement is greater than 100
    self.message += "DS18B20-1 Measured value is too High! Measurement is {meas}\n".format(meas=measurement)
    self.run_action("{7a3f837f}")  # Set LED - sense.set_pixel(0, 1, 255,0,0)
    self.logger.info("DS18B20-1 Measured value is > 100 {val}".format(val=measurement))

The Conditional Status CODE is:

   # Example code to provide a return status for other controllers and widgets.
pass

I’ve added self.logger.info just to see if the code is cycling, and mycodo.log shows that he code is:

2021-06-26 07:18:10,934 - INFO - mycodo.daemon - Mycodo daemon started in 7.081 seconds
2021-06-26 07:18:10,937 - INFO - mycodo.daemon - 70.27 MB RAM in use
2021-06-26 07:18:15,456 - INFO - mycodo.controllers.controller_conditional_49e87ba9 - DS18B20-1 Measured value is 69.575
2021-06-26 07:18:15,513 - INFO - mycodo.controllers.controller_conditional_49e87ba9 - DS18B20-1 Measured value < 80 69.575
2021-06-26 07:19:15,560 - INFO - mycodo.controllers.controller_conditional_49e87ba9 - DS18B20-1 Measured value is 69.575
2021-06-26 07:19:15,617 - INFO - mycodo.controllers.controller_conditional_49e87ba9 - DS18B20-1 Measured value < 80 69.575

BUT, none of the self.run_action("{0411875f}") work; none of the led’s light up.

However, if you replace the self.run_action("{0411875f}") with sense.set_pixel(0, 1, 0,0,255), the respective LED on the SenseHAT lights.

I created a 2nd Conditional Controller with NO Action. However, the Mycodo displays:

Info: Conditional activated without any Actions. Typical Conditional Controller use involves the use of Actions. Only proceed without Actions if you know what you’re doing.

Is there anyway to code the ACTION items, sense.set_pixel(0, 1, xxx,xxx,xxx), so they work?

As a side note I’m trying to learn python as I wrap my head around Mycodo.

Sincerely
Keith

I merged your two topics because they’re discussing the same thing.

About your use of the Shell Command, it’s not working because you’re trying to execute Python code in the shell. That simply will not work. You don’t need to create an action at all, just execute the Python code you need to in the Conditional Statement.

This statement indicates you have it all working.

The controller will work without Actions. It’s just informing you there are none. It’s not preventing the saving of settings or activation. In this case, we know what we’re doing.

OK thanks… I’m not a python programmer and I’m still trying to wrap my head around Mycodo… by the way if I haven’t said it " this program is outstanding!!!. I’ve tried several others and they just don’t have the flexibility you’ve created… I’ve corrupted the Mycodo so many time times that I’ve had to re-load the Mycodo more than a hand full, as such I want to make sure I’m doing it right and cut down on re-loading. With 6 DS18B20, and 2 DHT22’s ever-time I have to reload I have to re-create the gauges and graphs again.

yes it works with replacing the self.run_action("{0411875f}") with sense.set_pixel(0, 1, 0,0,255).

the only thing left to work out with the leds is, when I deactivate the Conditional Command the respective LEDs clear.

When you get your system in a working state, you can go to the Export page and export your settings to a file. You can then import that file in the future and restore your configuration on any Mycodo instance.

Also, what are you doing to cause this? Warnings and errors should be shown to the user to correct issues, but the system should not break (ideally), so if you can provide steps to replicate the issue, I’ll see about improving the error-handling.

Why would you need to deactivate the Conditional Controller?

You have a point…

I’ve been deactivating the Conditional Controller as I make changes to the code. Then I use a small program to clear the lights before re-activating the Conditional Controller in-order to check functionality of the code changes. But, once I have the code correct, I really wouldn’t have a need to deactivate the controller.

Thanks
Keith

What program did you use?

off-line I use part of the python senseHAT module… sense.clear()

Originally when asked why I wanted to turn the LEDs off I really didn’t have a need, other than checking code changes and LED assignments. But after playing with the program I realized I don’t the LEDs lit all night long. I only need a visual status when I’m up and about.

for Mycodo, I use a Conditional Controller without any Conditions or Actions only the Conditional Statement:

# Clears all the LEDs at a specific time

import datetime
from sense_hat import SenseHat
sense = SenseHat()

current = datetime.datetime.now()
clear_start = current.replace(hour=18, minute=5, second=0, microsecond=0)
clear_end = current.replace(hour=18, minute=6, second=0, microsecond=0)

if clear_start < current < clear_end:
    sense.clear()
    self.logger.info("**********  Cleared LEDs NOW  **********")

I hope this helps
Keith

1 Like