0

Funhouse wt Home Assistant
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Funhouse wt Home Assistant

by TWDM on Sun May 16, 2021 4:34 pm

New lessons include all libraries etc, seemingly an easier way to get things up and running. Load it all up and get endless errors in the library’s. Have loaded libraries from the library down load rather than the zip file, more of the same. Any advice would be appreciated.

TWDM
 
Posts: 51
Joined: Sat Sep 05, 2015 9:07 am

Re: Funhouse wt Home Assistant

by dastels on Sun May 16, 2021 6:39 pm

Could you post exactly what you are seeing? Copy & paste, please.

Dave

dastels
 
Posts: 7236
Joined: Tue Oct 20, 2015 3:22 pm

Re: Funhouse wt Home Assistant

by rbihler on Sun May 16, 2021 10:05 pm

I downloaded the Zip file, but used the current library's listed instead. I also updated the funhouse 6.2 uf2 file. Using 20210514 circuit python file.
I am not sure what I missed. Is this a program error or is it not connecting with the HA server.
I have updated the secrets file and looks like it's going to work. My home assistant is on 192.168.1.21 ip address.

Any suggestions are welcomed.
Thanks
Ron

code.py output:
Warning: Glyph clipped, exceeds descent property: "p"
Warning: Glyph clipped, exceeds descent property: "p"
Warning: Glyph clipped, exceeds descent property: "y"
Warning: Glyph clipped, exceeds descent property: "y"
Connecting to AP Netgear07
Attempting to connect to 192.168.1.21
Traceback (most recent call last):
File "code.py", line 144, in <module>
File "adafruit_funhouse/network.py", line 143, in mqtt_connect
File "adafruit_io/adafruit_io.py", line 110, in connect
File "adafruit_io/adafruit_io.py", line 110, in connect
AdafruitIO_MQTTError: MQTT Error: Unable to connect to Adafruit IO.

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

My code file.
Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import json
from adafruit_display_shapes.circle import Circle
from adafruit_funhouse import FunHouse

PUBLISH_DELAY = 60
ENVIRONMENT_CHECK_DELAY = 5
ENABLE_PIR = True
MQTT_TOPIC = "funhouse/state"
LIGHT_STATE_TOPIC = "funhouse/light/state"
LIGHT_COMMAND_TOPIC = "funhouse/light/set"
INITIAL_LIGHT_COLOR = 0x008000
USE_FAHRENHEIT = True

try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

funhouse = FunHouse(default_bg=0x0F0F00)
funhouse.peripherals.dotstars.fill(INITIAL_LIGHT_COLOR)

funhouse.display.show(None)
funhouse.add_text(
    text="Temperature:",
    text_position=(20, 30),
    text_color=0xFF8888,
    text_font="fonts/Arial-Bold-24.pcf",
)
temp_label = funhouse.add_text(
    text_position=(120, 60),
    text_anchor_point=(0.5, 0.5),
    text_color=0xFFFF00,
    text_font="fonts/Arial-Bold-24.pcf",
)
funhouse.add_text(
    text="Humidity:",
    text_position=(20, 100),
    text_color=0x8888FF,
    text_font="fonts/Arial-Bold-24.pcf",
)
hum_label = funhouse.add_text(
    text_position=(120, 130),
    text_anchor_point=(0.5, 0.5),
    text_color=0xFFFF00,
    text_font="fonts/Arial-Bold-24.pcf",
)
funhouse.add_text(
    text="Pressure:",
    text_position=(20, 170),
    text_color=0xFF88FF,
    text_font="fonts/Arial-Bold-24.pcf",
)
pres_label = funhouse.add_text(
    text_position=(120, 200),
    text_anchor_point=(0.5, 0.5),
    text_color=0xFFFF00,
    text_font="fonts/Arial-Bold-24.pcf",
)
funhouse.display.show(funhouse.splash)

status = Circle(229, 10, 10, fill=0xFF0000, outline=0x880000)
funhouse.splash.append(status)


def update_enviro():
    global environment

    temp = funhouse.peripherals.temperature
    unit = "C"
    if USE_FAHRENHEIT:
        temp = temp * (9 / 5) + 32
        unit = "F"

    environment["temperature"] = temp
    environment["pressure"] = funhouse.peripherals.pressure
    environment["humidity"] = funhouse.peripherals.relative_humidity
    environment["light"] = funhouse.peripherals.light

    funhouse.set_text("{:.1f}{}".format(environment["temperature"], unit), temp_label)
    funhouse.set_text("{:.1f}%".format(environment["humidity"]), hum_label)
    funhouse.set_text("{}kPa".format(environment["pressure"]), pres_label)


def connected(client, userdata, result, payload):
    status.fill = 0x00FF00
    status.outline = 0x008800
    print("Connected to MQTT! Subscribing...")
    client.subscribe(LIGHT_COMMAND_TOPIC)


def disconnected(client):
    status.fill = 0xFF0000
    status.outline = 0x880000


def message(client, topic, payload):
    print("Topic {0} received new value: {1}".format(topic, payload))
    if topic == LIGHT_COMMAND_TOPIC:
        settings = json.loads(payload)
        if settings["state"] == "on":
            if "brightness" in settings:
                funhouse.peripherals.dotstars.brightness = settings["brightness"] / 255
            else:
                funhouse.peripherals.dotstars.brightness = 0.3
            if "color" in settings:
                funhouse.peripherals.dotstars.fill(settings["color"])
        else:
            funhouse.peripherals.dotstars.brightness = 0
        publish_light_state()


def publish_light_state():
    funhouse.peripherals.led = True
    output = {
        "brightness": round(funhouse.peripherals.dotstars.brightness * 255),
        "state": "on" if funhouse.peripherals.dotstars.brightness > 0 else "off",
        "color": funhouse.peripherals.dotstars[0],
    }
    # Publish the Dotstar State
    print("Publishing to {}".format(LIGHT_STATE_TOPIC))
    funhouse.network.mqtt_publish(LIGHT_STATE_TOPIC, json.dumps(output))
    funhouse.peripherals.led = False


# Initialize a new MQTT Client object
funhouse.network.init_mqtt(
    secrets["mqtt_broker"],
    secrets["mqtt_port"],
    secrets["mqtt_port"],
    secrets["mqtt_username"],
    secrets["mqtt_password"],
)
funhouse.network.on_mqtt_connect = connected
funhouse.network.on_mqtt_disconnect = disconnected
funhouse.network.on_mqtt_message = message

print("Attempting to connect to {}".format(secrets["mqtt_broker"]))
funhouse.network.mqtt_connect()

last_publish_timestamp = None

last_peripheral_state = {
    "button_up": funhouse.peripherals.button_up,
    "button_down": funhouse.peripherals.button_down,
    "button_sel": funhouse.peripherals.button_sel,
    "captouch6": funhouse.peripherals.captouch6,
    "captouch7": funhouse.peripherals.captouch7,
    "captouch8": funhouse.peripherals.captouch8,
}

if ENABLE_PIR:
    last_peripheral_state["pir_sensor"] = funhouse.peripherals.pir_sensor

environment = {}
update_enviro()
last_environment_timestamp = time.monotonic()

# Provide Initial light state
publish_light_state()

while True:
    if not environment or (
        time.monotonic() - last_environment_timestamp > ENVIRONMENT_CHECK_DELAY
    ):
        update_enviro()
        last_environment_timestamp = time.monotonic()
    output = environment

    peripheral_state_changed = False
    for peripheral in last_peripheral_state:
        current_item_state = getattr(funhouse.peripherals, peripheral)
        output[peripheral] = "on" if current_item_state else "off"
        if last_peripheral_state[peripheral] != current_item_state:
            peripheral_state_changed = True
            last_peripheral_state[peripheral] = current_item_state

    if funhouse.peripherals.slider is not None:
        output["slider"] = funhouse.peripherals.slider
        peripheral_state_changed = True

    # Every PUBLISH_DELAY, write temp/hum/press/light or if a peripheral changed
    if (
        last_publish_timestamp is None
        or peripheral_state_changed
        or (time.monotonic() - last_publish_timestamp) > PUBLISH_DELAY
    ):
        funhouse.peripherals.led = True
        print("Publishing to {}".format(MQTT_TOPIC))
        funhouse.network.mqtt_publish(MQTT_TOPIC, json.dumps(output))
        funhouse.peripherals.led = False
        last_publish_timestamp = time.monotonic()

    # Check any topics we are subscribed to
    funhouse.network.mqtt_loop(0.5)

rbihler
 
Posts: 13
Joined: Sat Jan 24, 2015 10:29 pm

Re: Funhouse wt Home Assistant

by TWDM on Mon May 17, 2021 6:14 am

Tried the internet check code, it worked up until it found and reported a syntax error in my secrets file, a missing coma. That fixed that, everything works fine. Thank for your patience.

TWDM
 
Posts: 51
Joined: Sat Sep 05, 2015 9:07 am

Re: Funhouse wt Home Assistant

by dastels on Mon May 17, 2021 10:59 am

Excellent!

Dave

dastels
 
Posts: 7236
Joined: Tue Oct 20, 2015 3:22 pm

Re: Funhouse wt Home Assistant

by TWDM on Mon May 17, 2021 4:26 pm

Funhouse starts with clear colored lettering on black background. Over time yellow vertical streaks of various sizes develop on the black background all over the screen. Is this a known issue. Is it fixable?

TWDM
 
Posts: 51
Joined: Sat Sep 05, 2015 9:07 am

Re: Funhouse wt Home Assistant

by dastels on Mon May 17, 2021 4:38 pm

Like this: https://forums.adafruit.com/viewtopic.php?f=59&t=179310? My unit has been working steadily fine with no screen glitches.

Dave

dastels
 
Posts: 7236
Joined: Tue Oct 20, 2015 3:22 pm

Re: Funhouse wt Home Assistant

by TWDM on Mon May 17, 2021 4:46 pm

Yes that is what I see on the screen. Restarted my unit when sent the last email, the lines are back.

TWDM
 
Posts: 51
Joined: Sat Sep 05, 2015 9:07 am

Re: Funhouse wt Home Assistant

by TWDM on Tue May 18, 2021 8:42 am

Is it possible that the funhouse is light sensitive? Rebooted it in a un-lite dim room and screen background was fine for over an hour. When I shined a flashlight on the funhouse, the vertical lines started showing up immediately. Just wondering?

TWDM
 
Posts: 51
Joined: Sat Sep 05, 2015 9:07 am

Re: Funhouse wt Home Assistant

by dastels on Tue May 18, 2021 8:48 am

As per the other post, it seems to be an issue with CircuitPython and not the hardware. It appears to be under investigation.

Dave

dastels
 
Posts: 7236
Joined: Tue Oct 20, 2015 3:22 pm

Re: Funhouse wt Home Assistant

by dastels on Tue May 18, 2021 8:52 am

Re: the light sensitivity theory. That'd be weird. I tried that with mine and don't see any reaction to a bright light shone on it. Also mine has been running for days with a environmental display (based on the code you are using), PIR, and HUE light control. It's been fine. Stay tuned.

You'd mentioned that you're using the latest CP and bundle, correct?

Dave

dastels
 
Posts: 7236
Joined: Tue Oct 20, 2015 3:22 pm

Re: Funhouse wt Home Assistant

by TWDM on Fri May 21, 2021 6:48 pm

Adabox 018, set up LIFX sketch, the same vertical lines showed up, changed some of the colors in the “code.py”, the lines have disappeared, been running for a couple of hours.

TWDM
 
Posts: 51
Joined: Sat Sep 05, 2015 9:07 am

Re: Funhouse wt Home Assistant

by jerryn on Fri May 21, 2021 10:02 pm

FYI -- the glitches are a known issue for the CircuitPython -- see this issue in the Github repository https://github.com/adafruit/circuitpython/pull/4793#issuecomment-846194187

jerryn
 
Posts: 1539
Joined: Sat Sep 14, 2013 9:05 am

Re: Funhouse wt Home Assistant

by TWDM on Sat May 22, 2021 2:24 pm

The PyPortal MQTT Sensor Node/Control Pad
https://learn.adafruit.com/pyportal-mqt ... ython-code

Maybe new topic, but for me HA and MQTT issues

any help appreciated, thanks


Connected to WiFi!
Traceback (most recent call last):
File "code.py", line 233, in <module>
TypeError: 'module' object is not callable

Code done running.
[/code]

[code]# Set up a MiniMQTT Client
client = MQTT(
broker=secrets["broker"],
port=1883,
username=secrets["user"],
password=secrets["pass"],
)/code]

password=secrets["pass"], - is line 233

TWDM
 
Posts: 51
Joined: Sat Sep 05, 2015 9:07 am

Re: Funhouse wt Home Assistant

by rbihler on Sat May 22, 2021 11:01 pm

I was able to get the Funhouse and HA example running. It's working very well, I had to used the sample library's only.

Has anyone connected a DHT22 or DHT11 to the funhouse. It's great it has a temp sensor on the board, just very sad that it heats up.
I did try to DHT library and connect DHT11 to the funhouse on board.a0 port. I get a checksum error and can't seem to get past that. It does have a pullup on the data line.
dht = adafruit_dht.DHT11(board.A0) is the code. Do I need to use a different location or pins.

I made up a garage logger system in the past using Arduino code. It would read the temp (Check for freezing), use a distance sensor to see if the door was up or down and check if I left the light on. The fun house is a cleaner system and seems like it was made for this type of application other than the temp problem.

I thought adding the DHT would be simple but than again.

Ron

rbihler
 
Posts: 13
Joined: Sat Jan 24, 2015 10:29 pm

Please be positive and constructive with your questions and comments.