Skip to content

Home assistant Basics und LDR config #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3418584
Add files via upload
sogidaned Mar 7, 2025
b880953
Merge pull request #1 from sogidaned/Bayerisches-Layout
sogidaned Mar 7, 2025
a5605aa
Update DE10x11.bayerisch.hpp
sogidaned Mar 7, 2025
e4b691d
add bavarian layout
sogidaned Mar 8, 2025
cd8e77b
add bavarian layout
sogidaned Mar 8, 2025
8b06d7f
add bavarian layout
sogidaned Mar 8, 2025
055ce43
add bavarian layout
sogidaned Mar 8, 2025
ae7d920
add bavarian layout
sogidaned Mar 8, 2025
31126c6
add bavarian layout
sogidaned Mar 8, 2025
8135ad2
add bavarian layout
sogidaned Mar 8, 2025
5239ac3
add bavarian layout
sogidaned Mar 8, 2025
2d54cee
"de-10-11-bayerisch": "🇩🇪 10 × 11 bavarese",
sogidaned Mar 8, 2025
7a36f38
add bavarian layout
sogidaned Mar 8, 2025
664c524
add bavarian layout
sogidaned Mar 8, 2025
79fbd58
Merge pull request #2 from sogidaned/Bayerisches-Layout
sogidaned Mar 8, 2025
f6dfa13
ldr auswahl und homeassistant verbesserung
sogidaned Mar 10, 2025
430c486
Update platformio.yml
sogidaned Mar 10, 2025
0026935
Update platformio.yml
sogidaned Mar 10, 2025
d3666d7
Update clang-format.yml
sogidaned Mar 10, 2025
34ebf12
Merge pull request #3 from sogidaned/ldr_auswahl
sogidaned Mar 10, 2025
b58c4af
clang-format tet
sogidaned Mar 10, 2025
d51a38f
test 2
sogidaned Mar 10, 2025
40ab823
hoffendlich letzter test
sogidaned Mar 10, 2025
ac17a70
test4
sogidaned Mar 10, 2025
2c3968c
Stufe 1 Fertig
sogidaned Mar 10, 2025
067c303
MQTT-Implementierung optimiert: Vereinfachung und Bereinigung der Fun…
sogidaned Mar 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: DoozyX/clang-format-lint-action@v0.18.2
with:
source: '.'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Expand Down
4 changes: 4 additions & 0 deletions include/Uhr.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ struct GLOBAL {
bool bootShowIP;

Birthday birthday[MAX_BIRTHDAY_COUNT];

uint8_t ldrType; // 0 = 1 LDR, 1 = 4 LDR parallel
};
GLOBAL G = {};

Expand Down Expand Up @@ -253,6 +255,7 @@ enum CommandWords {
COMMAND_SET_AUTO_BRIGHT = 102,
COMMAND_SET_LAYOUT_VARIANT = 103,
COMMAND_SET_MQTT_HA_DISCOVERY = 104,
COMMAND_SET_LDR_TYPE = 105,

COMMAND_SPEED = 152,

Expand All @@ -279,6 +282,7 @@ enum ClockType {
Ger10x11schwaebisch = 20,
Ger10x11Nero = 11,
Ger10x11NeroFrame = 26,
Ger10x11bayerisch = 27,
Ger11x11 = 3,
Ger11x11V2 = 8,
Ger11x11V3 = 14,
Expand Down
134 changes: 134 additions & 0 deletions include/Uhrtypes/DE10x11.bayerisch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#pragma once

#include "Uhrtype.hpp"

/*
* Layout Front
* COL
* X 9 8 7 6 5 4 3 2 1 0
* ROW + - - - - - - - - - - -
* 0 | E T Z K I S T F Ü N F
* 1 | Z E H N E Z W A N Z G
* 2 | D R E I V I E R T L E
* 3 | J T N O C H V O R X M
* 4 | H O I B E P Z D R E I
* 5 | Z W O A N S S I E M E
* 6 | K A C H T E F Ü N F E
* 7 | N E I N E V I E R E Q
* 8 | Z W O I F E Z E H N E
* 9 | Y S E C H S E F U H R
*/

class De10x11bayerisch_t : public iUhrType {
public:
virtual LanguageAbbreviation usedLang() override {
return LanguageAbbreviation::DE;
};

//------------------------------------------------------------------------------

virtual const bool hasDreiviertel() override { return true; }

//------------------------------------------------------------------------------

void show(FrontWord word) override {
switch (word) {

case FrontWord::es_ist:
setFrontMatrixWord(0, 8, 10);
setFrontMatrixWord(0, 5, 6);
break;

case FrontWord::nach:
case FrontWord::v_nach:
setFrontMatrixWord(3, 5, 8);
break;

case FrontWord::vor:
case FrontWord::v_vor:
setFrontMatrixWord(3, 2, 4);
break;

case FrontWord::viertel:
setFrontMatrixWord(2, 1, 6);
break;

case FrontWord::dreiviertel:
setFrontMatrixWord(2, 1, 10);
break;

case FrontWord::min_5:
setFrontMatrixWord(0, 0, 3);
break;

case FrontWord::min_10:
setFrontMatrixWord(1, 7, 10);
break;

case FrontWord::min_20:
setFrontMatrixWord(1, 0, 5);
break;

case FrontWord::halb:
setFrontMatrixWord(4, 6, 10);
break;

case FrontWord::eins:
setFrontMatrixWord(5, 5, 8);
break;

case FrontWord::hour_1:
setFrontMatrixWord(5, 5, 8);
break;

case FrontWord::hour_2:
setFrontMatrixWord(5, 7, 10);
break;

case FrontWord::hour_3:
setFrontMatrixWord(4, 0, 3);
break;

case FrontWord::hour_4:
setFrontMatrixWord(7, 1, 5);
break;

case FrontWord::hour_5:
setFrontMatrixWord(6, 0, 4);
break;

case FrontWord::hour_6:
setFrontMatrixWord(9, 4, 9);
break;

case FrontWord::hour_7:
setFrontMatrixWord(5, 0, 4);
break;

case FrontWord::hour_8:
setFrontMatrixWord(6, 5, 9);
break;

case FrontWord::hour_9:
setFrontMatrixWord(7, 6, 10);
break;

case FrontWord::hour_10:
setFrontMatrixWord(8, 0, 4);
break;

case FrontWord::hour_11:
setFrontMatrixWord(8, 5, 8);
break;

case FrontWord::hour_12:
setFrontMatrixWord(8, 5, 10);
break;

default:
break;
};
};
};

De10x11bayerisch_t _de10x11bayerisch;
9 changes: 9 additions & 0 deletions include/clockWork.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ class ClockWork {
//------------------------------------------------------------------------------
iUhrType *getPointer(uint8_t type);
void initLedStrip(uint8_t num);
float getLuxValue() const { return lux; }
float getAdcValue() const {
uint16_t adcRaw = analogRead(A0);
float voltage = (adcRaw * 3.3f) / 1023.0f;
return round(voltage * 100.0f) / 100.0f; // Runde auf 2 Nachkommastellen
}
uint16_t getAdcRawValue() const {
return analogRead(A0); // Roher ADC-Wert (0-1023)
}

//------------------------------------------------------------------------------
// Minute Functions
Expand Down
24 changes: 17 additions & 7 deletions include/clockWork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@ void ClockWork::loopAutoBrightLogic() {
if (adcValue < adcValue0Lux)
adcValue0Lux = adcValue;
float ldrValue = adcValue - adcValue0Lux;
// Derive LUX value from ldrValue via a second degree polinomial.
// The polinomial was derived using an Excel trend line, see
// LDR-Calibration.xlsx
const float x2 = 0.0427;
const float x1 = 2.679;
const float x0 = 10.857;
lux = x2 * ldrValue * ldrValue + x1 * ldrValue + x0;

// Derive LUX value from ldrValue via a second degree polinomial
// based on LDR type
if (G.ldrType == 0) { // 1 LDR Sensor
const float x2 = 0.0427;
const float x1 = 2.679;
const float x0 = 10.857;
lux = x2 * ldrValue * ldrValue + x1 * ldrValue + x0;
} else { // 4 LDR Sensoren parallel
const float x2 = 0.0005;
const float x1 = 0.0687;
const float x0 = 3.9907;
lux = x2 * ldrValue * ldrValue - x1 * ldrValue + x0;
}
}

// Based on the LUX value derive the gain for the LEDs 0.0 - 100.0%
Expand Down Expand Up @@ -104,6 +111,8 @@ iUhrType *ClockWork::getPointer(uint8_t type) {
return &_de10x11Nero;
case Ger10x11NeroFrame:
return &_de10x11NeroFrame;
case Ger10x11bayerisch:
return &_de10x11bayerisch;
case Nl10x11:
return &_nl10x11;
case Ger11x11:
Expand Down Expand Up @@ -1176,6 +1185,7 @@ void ClockWork::loop(struct tm &tm) {
config["bootShowWifi"] = G.bootShowWifi;
config["bootShowIP"] = G.bootShowIP;
config["autoBrightEnabled"] = G.autoBrightEnabled;
config["ldrType"] = G.ldrType;
config["isRomanLanguage"] = isRomanLanguage();
config["hasDreiviertel"] = usedUhrType->hasDreiviertel();
config["hasZwanzig"] = usedUhrType->hasZwanzig();
Expand Down
14 changes: 10 additions & 4 deletions include/mqtt.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
#pragma once

#include <Arduino.h>
#include "Uhr.h"
#include "clockWork.h"
#include <ArduinoJson.h>

class Mqtt {
private:
ClockWork &clockWork; // Referenz auf ClockWork-Instanz
void reInit();
static void callback(char *topic, byte *payload, unsigned int length);
static void processState(const JsonDocument &doc);
static void processEffect(const JsonDocument &doc);
static void processScrollingText(const JsonDocument &doc);
static void processColor(const JsonDocument &doc);
static void processBrightness(const JsonDocument &doc);
static bool checkIfMqttUserIsEmpty();

public:
Mqtt() = default;
~Mqtt() = default;
Mqtt(ClockWork &cw);
~Mqtt();

void init();
void loop();
void sendState();
void sendDiscovery();

bool isConnected();
};

// Globale Instanz
extern Mqtt *mqttInstance;
Loading