HA SwitchPlate HASPone: DIY In-Wall Touchscreen Home Assistant Controller

Nice use of the for loops.

here you can find the color codes from Nextion: https://www.itead.cc/wiki/Nextion_Instruction_Set#Nextion_HMI:_Color_Code_List

@luma
Iā€™ve been enjoying my new HAswitchplate when some strange behavior made the device unusable; iā€™m hoping someone might have some insight.

Everything was working fine, then the display stopped turning on. I was still able to press the screen and the lights configured for that button would respond, however the screen appeared off. I tried to access the web UI and was unable to. After a rebooting the device, the web UI was displayed, however the the screen would never come back onā€¦
Thinking this was a user error, I bought a whole new setup, new screen, new wemos D1 mini and everything worked fineā€¦ until the screen would no longer come back onā€¦ Pressing the screen does send MQTT messages (the lights respond) but the screen will not come onā€¦ Both instances of this issue appeared roughly about a week after installation.
If I take a screen that wonā€™t come on, put the SD card in, and apply 5v, the screen comes on! during the update process ā€¦once back in the HAswitchplate setup, the screen does not come onā€¦
Iā€™m not sure that the screen is totaled since it can receive input, and it can turn on since it did so with the SD cardā€¦
Home assistant sees it as connected and onlineā€¦ the Web UI sees it as onlineā€¦
Toggling the backlight toggle doesnā€™t turn on the screenā€¦

Any ideas?

check what the backlight dimmer is set to in HA. I had the issue and toggling the backlight did nothing, but that was because my backlight was set to 0. Once I moved the dimmer slider the backlight came back on.

1 Like

@michael.leone I love your design, any change to share the STL files? Or when they are online already, can you point me to the location where I can find them? :slight_smile:

Thank you!
I didnā€™t even think to check if there was a sliderā€¦

Itā€™s working great again!
Thanks!

Ok went through the complete thread to see if anyone posted about an issue iā€™m seeing. I didnā€™t see anything related so Iā€™ll go ahead and ask. So I am setting up my HASP, things seem to be working as I can update menu names and control my media player and such. The issue iā€™m having is after some time (havenā€™t timed it exactly letā€™s just say 20 minutes) the display reverts back to the main setup screen. After connecting and going to the settings I can see the wifi setting have been cleared. While troubleshooting this I even experienced my mqtt password settings clearing. I flashed another esp8266 to see if that would resolve the issue but the same thing happens there. Iā€™m going to keep working on it to see if I can find a resolution but I wanted to post just in case someone had an similar issue or perhaps has some ideas on things to check. Other WiFi connected devices work just fine.

The improvements @michael.leone did are merged into these?

I think youā€™re looking at rendered designs for Australian work boxes. Iā€™ll accept PRs for any tested solutions for enclosures outside of NA, but I am unable to design and test anything like that myself for lack of access to standard work boxes from around the world.

Ah, I thought there were PRā€™s based on those rendered design. My bad. Too bad.

HASP 0.31 release

New release of the Arudino code brings back motion sensor support, enhanced reliability, and several bugfixes. New Home Assistant Automations have been published which should cut down on MQTT traffic (yay duplicate subscription handling in hass) and increase reliability.

Arduino code v0.31

  • Added motion sensor support on pins D0/D1/D2, configurable via web interface
  • BREAKING CHANGE! MQTT namespace for backlight changed status to state. If using backlight automations you will need to change this, and also modify hasp_plate01_00_components.yaml (or re-run deployhasp.sh to bring down the new automations, which you should do anyway).
  • mDNS support
  • Better handling of WiFi connection process
  • Force device name to lower case in web config
  • Cleanup of MQTT subscriptions and better handling of new/existing connections

Home Assistant Automations

  • Removed HASP power-on MQTT subscriptions to get rid of duplicate messages being sent by Home Assistant. The binary_sensor device is now used for all automations to detect the device coming online
  • Changes to file structure to allow examples to be renamed via deployhasp.sh without filling hass log full of errors. If youā€™d like to utilize functions like Media Player or 3D printer monitoring, youā€™ll need to copy over the relevant .yaml files from hasp-examples/plate01/<filename>.yaml to your packages folder.
  • Replace deprecated weather API sources
  • Refresh automation group at startup (Thanks @Nightcat!)

If youā€™re using the AutoFirmwareUpdate automation your devices should pull this update at 3:00am. Otherwise, log into the admin web page and you can pull the update from the firmware page.

1 Like

Oh man I need to test this out again. I moved since I first implemented this (pre v0.2) and just recently got some basic home automation stuff set back up. I remember the MQTT issues being an absolute pain and causing the screen to become unresponsive for a period of time. Hacked my own fixes in place but never tried out your subsequent releases.

Have hit a bit of a brick-wall with the Volume Slider in the media player.

When adjusting the volume of the media player in HASS (to push this to the HASP), utilising the following entry in automations.yaml throws me a 0 regardless of the value of the slider:

- alias: 'Update Volume'
    trigger:
      - platform: state
        entity_id: sensor.media_player_volume
    action:
      - service: mqtt.publish
        data:
          payload_template: '{{ (states.sensor.media_player_volume.state * 100)|int }}'
          topic: hasp/plate01/command/p[1].b[5].val

If I remove the |int from the message, I get the following having set the volume to 0.85 on the media player:

0.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.850.85

Iā€™ve not taken the time to count, but presumably is 100 0.850s (!)

Then finally if I remove the * 100, it gives me a value of 0.85

Any ideas on how I can get the calculation to work properly?

Thanks in advance!

Nevermind I figured it out - the initial sensor was not being picked up as an int hence the calculation not completing correctly. For reference, this worked:

  - alias: 'Update Volume'
    trigger:
      - platform: state
        entity_id: sensor.media_player_volume
    action:
      - service: mqtt.publish
        data:
          payload_template: '{{ ((states.sensor.media_player_volume.state|float) * 100|int)|int }}'
          topic: hasp/plate01/command/p[1].b[5].val
1 Like

@luma what motion sensor are you using? got a link?

Iā€™m back to testing out the RCWL-0516 radar module which you can get for about $0.40/pc. It doesnā€™t work very well but I wanted to kick around some ideas and figured others might want to use a PIR sensor or whatever. I threw together a quick shield to mount it inside the case with a small strip of protoboard plugged into the breakout connector:


1 Like

I added one of these just now and it works decently.

1 Like

I test the sensor Ultrasonic Module HC-SR04, it works fine.
aliexpress

1 Like

I got 2 problems since the latest release:

  1. The switchplate doesnā€™t seem to remember my SSID and Password. So it reset itself from time to time, to the AP mode. Found in the code comments that shutting off auto firmware update should solve this problem?

  2. Sometime after reconfiguring the switchplate, the plate only show MQTT and WIFI connected with correct IP and the following message: ā€œfailed to connect RC=5 retry in 10sā€

Anyone else had those issues? And how did you solve them?

Both of these may be related to the same problem which I have set for the next release. When you click ā€œsaveā€ in the HASP web interface it just blindly saves whatever is in each field. This includes password fields, which donā€™t have the password inserted as a default, so every time you click ā€œsaveā€ without re-entering the passwords it will wipe them out. For the moment, just make sure you enter the password any time you need to click ā€œsaveā€ in the main web page (which shouldnā€™t be often), and I should have this sorted here soon.

For reference, the RC=n is the return code from the MQTT client connection, which is specified by the MQTT spec here.

Value Return Code Response Description
0 0x00 Connection Accepted Connection accepted
1 0x01 Connection Refused, unacceptable protocol version The Server does not support the level of the MQTT protocol requested by the Client
2 0x02 Connection Refused, identifier rejected The Client identifier is correct UTF-8 but not allowed by the Server
3 0x03 Connection Refused, Server unavailable The Network Connection has been made but the MQTT service is unavailable
4 0x04 Connection Refused, bad user name or password The data in the user name or password is malformed
5 0x05 Connection Refused, not authorized The Client is not authorized to connect
6-255 Reserved for future use