Adresovatelná mapa ČR

www
Odpovědět
kiklhorn
Moderátor
Moderátor
Příspěvky: 901
Registrován: 03. červenec 2021, 18:35
Dal poděkování: 107 poděkování
Dostal poděkování: 210 poděkování

Adresovatelná mapa ČR

Příspěvek od kiklhorn »

Mapa ČR,
každý okres jedna RGB LEDka.

Objednání a dokumentace viz: https://github.com/tomasbrincil/pcb_mapa_cr_1


DSC_1492.JPG
Co se má zobrazit je definováno ve volitelném efektu.
webInterface.jpg
Aktuálně dvě různá zobrazení teplot z TMEP.CZ
Není problém dodělat další - třeba výsledky voleb, nebo cokoliv zobrazitelného "po okresech", nebo přidat "nějaké blikání"

yaml pro ESPHome:

Kód: Vybrat vše

esphome:
  name: rgbcrmap
  includes:
    - wheel.h
  on_boot: 
    priority: -100
    then:
      - script.execute: getTemperaturesData

esp32:
  board: esp32doit-devkit-v1

# Enable logging
logger:

web_server:
  

# Enable Home Assistant API
api:
  encryption:
    key: "ZXINxDk5Sk8o4+dS6XveJ2qurVltdoWJKurU/mVevns="

ota:
  password: "b93d1d0149cede226333702f570533e5"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rgbcrmap Fallback Hotspot"
    password: "BfPrNYK8vZ83"

captive_portal:

globals:
  - id: tempData
    type: String
    restore_value: False
    initial_value: '"{}"'

light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812
    pin: GPIO13
    # method: 
    num_leds: 77
    name: "NeoPixel Light"
    id: neo
    default_transition_length: 
      seconds: 0

  # - platform: fastled_clockless
  #   chipset: WS2812B
  #   pin: GPIO13
  #   # method: 
  #   num_leds: 77
  #   rgb_order: GRB
  #   name: "NeoPixel Light"
  #   id: neo
  #   default_transition_length: 
  #     seconds: 0
    effects:
      - addressable_color_wipe:
      - addressable_color_wipe:
          name: Color Wipe Effect With Custom Values
          colors:
            - red: 100%
              green: 100%
              blue: 100%
              num_leds: 1
            - red: 0%
              green: 0%
              blue: 0%
              num_leds: 1
          add_led_interval: 100ms
          reverse: false
      - addressable_lambda:
          name: "Mapa teplot TMEP @tvoje___mama"
          update_interval: 3000ms
          lambda: |-
            DynamicJsonDocument doc(6144);
            Serial.println(id(tempData));
            DeserializationError error = deserializeJson(doc, id(tempData));
            if (error) {
              Serial.print("deserializeJson() failed: ");
              Serial.println(error.c_str());
              return;
            }
            for (JsonObject item : doc.as<JsonArray>()) {
              int ledIndex = item["id"]; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ...
              ledIndex -= 1;
              double h = item["h"]; // -0.6, -4.3, -2.2, -1.5, -0.5, -0.5, 0.9, -0.4, -2.5, -0.5, -2.2, -3.4, -3.9, ...
              int color = map(h, -15, 40, 170, 0);
              //it[ledIndex] = Wheel(color);
              it[ledIndex] = WheelAda(color); //Adafruit values - podivej se do wheel.h, jsou tam odkazy
              serialPrintf("okres: %d, teplota: %f, barva rgb: (Wheel/WheelAda) %d/%d %d/%d %d/%d\n",ledIndex,h,Wheel(color)[0],WheelAda(color)[0],Wheel(color)[1],WheelAda(color)[1],Wheel(color)[2],WheelAda(color)[2]);
            }
            //id(neo).turn_on().set_brightness(0.99).perform();
      - addressable_lambda:
          name: "Mapa teplot TMEP @jirka1213"
          update_interval: 3000ms
          lambda: |-
            double maxTemp = -99;
            double minTemp =  99;
            DynamicJsonDocument doc(6144);
            Serial.println(id(tempData));
            DeserializationError error = deserializeJson(doc, id(tempData));
            if (error) {
              Serial.print("deserializeJson() failed: ");
              Serial.println(error.c_str());
              return;
            }
            //Zjisti min a max teplotu pro mapping
            for (JsonObject item : doc.as<JsonArray>()) {
              double h = item["h"];
              if (h < minTemp) minTemp = h;
              if (h > maxTemp) maxTemp = h;
            }

            for (JsonObject item : doc.as<JsonArray>()) {
              int ledIndex = item["id"]; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ...
              ledIndex -= 1;
              double h = item["h"]; // -0.6, -4.3, -2.2, -1.5, -0.5, -0.5, 0.9, -0.4, -2.5, -0.5, -2.2, -3.4, -3.9, ...
              int color = map(h, minTemp, maxTemp, 170, 0);
              //it[ledIndex] = Wheel(color);
              it[ledIndex] = WheelAda(color); //Adafruit values - podivej se do wheel.h, jsou tam odkazy
              serialPrintf("okres: %d, teplota: %f, barva rgb: (Wheel/WheelAda) %d/%d %d/%d %d/%d\n",ledIndex,h,Wheel(color)[0],WheelAda(color)[0],Wheel(color)[1],WheelAda(color)[1],Wheel(color)[2],WheelAda(color)[2]);
            }
            //id(neo).turn_on().set_brightness(0.99).perform();

json:

http_request:
  id: http_request_data
  useragent: esphome/rgbcrmap
  timeout: 10s

async_tcp:

# https://arduinojson.org/v6/assistant/#/step1
time:
  - platform: sntp
    on_time:
      - seconds: 0
        minutes: /10
        then:
          - script.execute: getTemperaturesData

script:
  - id: getTemperaturesData
    mode: queued
    then:
      - logger.log:
          level: info
          format: "HTTP Request get Data"
      - http_request.get:
          url: "http://cdn.tmep.cz/app/export/okresy-cr-teplota.json"
          headers:
            Content-Type: application/json
          verify_ssl: false
          on_response:
            - if:
                condition:
                  lambda: |-
                    return status_code == 200;  
                then:
                  - logger.log:
                      level: info
                      tag: "getTemperaturedata"
                      format: "Response status: %d, Duration: %u ms"
                      args:
                        - status_code
                        - duration_ms  
                  - lambda: |- 
                      //String tempData;
                      id(tempData) = id(http_request_data).get_string();


Kód wheel.h:
soubor uložit tam kde je yaml

Kód: Vybrat vše

// https://votecharlie.com/blog/2018/08/improved-color-wheel-function.html
// Adapted from https://www.stm32duino.com/viewtopic.php?t=56#p8160
unsigned int sqrt32(unsigned long n) {
    unsigned int c = 0x8000;
    unsigned int g = 0x8000;
    while(true) {
    if(g*g > n) {
        g ^= c;
    }
    c >>= 1;
    if(c == 0) {
        return g;
    }
    g |= c;
    }
}

// Input values 0 to 255 to get color values that transition R->G->B. 0 and 255
// are the same color. This is based on Adafruit's Wheel() function, which used
// a linear map that resulted in brightness peaks at 0, 85 and 170. This version
// uses a quadratic map to make values approach 255 faster while leaving full
// red or green or blue untouched. For example, Wheel(42) is halfway between
// red and green. The linear function yielded (126, 129, 0), but this one yields
// (219, 221, 0). This function is based on the equation the circle centered at
// (255,0) with radius 255:  (x-255)^2 + (y-0)^2 = r^2
Color Wheel(byte position) {
    byte R = 0, G = 0, B = 0;
    if (position < 85) {
    R = sqrt32((1530 - 9 * position) * position);
    G = sqrt32(65025 - 9 * position * position);
    } else if (position < 170) {
    position -= 85;
    R = sqrt32(65025 - 9 * position * position);
    B = sqrt32((1530 - 9 * position) * position);
    } else {
    position -= 170;
    G = sqrt32((1530 - 9 * position) * position);
    B = sqrt32(65025 - 9 * position * position);
    }
    return Color(R, G, B);
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
Color WheelAda(byte WheelPos) {
    WheelPos = 255 - WheelPos;
    if(WheelPos < 85) {
        return Color(255 - WheelPos * 3, 0, WheelPos * 3);
    }
    if(WheelPos < 170) {
        WheelPos -= 85;
        return Color(0, WheelPos * 3, 255 - WheelPos * 3);
    }
    WheelPos -= 170;
    return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

//https://medium.com/@kslooi/print-formatted-data-in-arduino-serial-aaea9ca840e3
#include <stdarg.h>
#define SERIAL_PRINTF_MAX_BUFF      256
void serialPrintf(const char *fmt, ...);
void serialPrintf(const char *fmt, ...) {
    /* Buffer for storing the formatted data */
    char buff[SERIAL_PRINTF_MAX_BUFF];
    /* pointer to the variable arguments list */
    va_list pargs;
    /* Initialise pargs to point to the first optional argument */
    va_start(pargs, fmt);
    /* create the formatted data and store in buff */
    vsnprintf(buff, SERIAL_PRINTF_MAX_BUFF, fmt, pargs);
    va_end(pargs);
    Serial.print(buff);
}
více zde: https://chiptron.cz/news.php?readmore=1441
Přílohy
DSC_1487.JPG
DSC_1486.JPG
Vše co si přinesu domů je buď Shelly, nebo to skončí buď pod ESPhome nebo pod Zigbee2mqtt.
Ajťák co pamatuje BBS a OS/2 Warp a je mu jedno o jaký systém nebo síťařinu běží.
HA OS jako jedna z Proxmox VM na Odroid H3+/64GB https://github.com/tteck/Proxmox

Tommm
Nováček na fóru
Nováček na fóru
Příspěvky: 1
Registrován: 09. březen 2023, 10:01
Dal poděkování: 1 poděkování

Re: Adresovatelná mapa ČR

Příspěvek od Tommm »

Ahoj, je to super, ale dneska se mi zdála mapa kompletně zelená. Porovnával jsem to s originálním FW. a barvičky ve tvojí implementaci "Tvoje__máma" mapy jsou jinak.Čím to může být? Viz foto: (nahoře originál FW z githubu, dole ESPHome)
Koukám teď na fotky a z toho mobilu to neleze tak jasně viditelné, jako pouhým okem. Například severní hory jsou u origo FW tyrkysové (studenější) než zbytek ČR. U ESPHome je od pohledu mapa kompletně zelená stejnou barvou.
Přílohy
org_FW.jpg
ESPHome.jpg

kiklhorn
Moderátor
Moderátor
Příspěvky: 901
Registrován: 03. červenec 2021, 18:35
Dal poděkování: 107 poděkování
Dostal poděkování: 210 poděkování

Re: Adresovatelná mapa ČR

Příspěvek od kiklhorn »

Ahoj,
číslo na barvu se převádí přes funkci WheelAda() v souboru wheel.h která by dle uvedeného odkazu "měla" odpovídat té v knihovně použité v originálu.

Netuším zda je problém ve funkci, nebo zda vrácené teploty z TMEP byly všechny stejné, podle barvy odhaduji 0.

Do sériové linky jsou logovány údaje o načtených teplotách i vygenerovaných barvách - pokud by to ještě nastalo tak bych poprosil o nakopírování.

Zkusím udělat ještě nějaký další efekt na otestování celého rozsahu barev.
A senzor předávající teploty pro další použití v HA.
Vše co si přinesu domů je buď Shelly, nebo to skončí buď pod ESPhome nebo pod Zigbee2mqtt.
Ajťák co pamatuje BBS a OS/2 Warp a je mu jedno o jaký systém nebo síťařinu běží.
HA OS jako jedna z Proxmox VM na Odroid H3+/64GB https://github.com/tteck/Proxmox

kiklhorn
Moderátor
Moderátor
Příspěvky: 901
Registrován: 03. červenec 2021, 18:35
Dal poděkování: 107 poděkování
Dostal poděkování: 210 poděkování

Re: Adresovatelná mapa ČR

Příspěvek od kiklhorn »

Pokračování:
Dávám další pracovní verzi.

Přidán efekt - barvičky po jednotlivých krajích.
Přidán efekt kdy udělá gradient 5 stupňů přes celou mapu postupně v rozsahu teplot -15 až + 40
V sériovém logu jsou vidět rovnou názvy okresů k teplotám.

rgbcrmap.yaml:

Kód: Vybrat vše

esphome:
  name: rgbcrmap
  includes:
    - wheel.h
    # - tinyxml2.h
    # - tinyxml2.cpp
    - okres.h
    # - <esp_task_wdt.h>
    # esp_task_wdt_init(15 /* timeout */, false /* panic */);
    # - libs/xml2json/rapidxml
    # - libs/xml2json/rapidjson
    # - libs/xml2json/xml2json.hpp

  on_boot: 
    priority: -100
    then:
      - script.execute: getTemperaturesData

esp32:
  board: esp32doit-devkit-v1
  framework: 
    type: arduino

# Enable logging
logger:

web_server:
  # js_include: "./v2/www.js"
  # js_url: ""
  # version: 2
  
# custom_component:
#     - lambda: |-
#         auto my_custom = new EggCooker(id(secs),id(state));
#         App.register_component(my_custom);
#         return {my_custom};

# Enable Home Assistant API
api:
  encryption:
    key: "ZXINxDk5Sk8o4+dS6XveJ2qurVltdoWJKurU/mVevns="

ota:
  password: "b93d1d0149cede226333702f570533e5"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: True

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rgbcrmap Fallback Hotspot"
    password: "BfPrNYK8vZ83"

captive_portal:

globals:
  - id: tempData
    type: String
    restore_value: False
    initial_value: '"{}"'
  - id: vote1Data
    type: String
    restore_value: False


light:
  - platform: neopixelbus
    # restore_mode: ALWAYS_OFF
    type: GRB
    variant: WS2812
    pin: GPIO13
    # method: 
    num_leds: 77
    name: "NeoPixel Light"
    id: neo
    default_transition_length: 
      seconds: 0

  # - platform: fastled_clockless
    # chipset: WS2812B
    # pin: GPIO13
    # # method: 
    # num_leds: 77
    # rgb_order: GRB
    # name: "NeoPixel Light"
    # id: neo
    # default_transition_length: 
    #   seconds: 0
    effects:
      - addressable_color_wipe:
      - addressable_color_wipe:
          name: Color Wipe Effect With Custom Values
          colors:
            - red: 100%
              green: 100%
              blue: 100%
              num_leds: 1
            - red: 0%
              green: 0%
              blue: 0%
              num_leds: 1
          add_led_interval: 100ms
          reverse: false
      - addressable_lambda:
          name: "Mapa teplot TMEP @tvoje___mama Adafruit Wheel"
          update_interval: 5s
          lambda: |-
            //id(getTemperaturesData).execute();
            DynamicJsonDocument doc(6144);
            Serial.println(id(tempData));
            DeserializationError error = deserializeJson(doc, id(tempData));
            if (error) {
              Serial.print("deserializeJson() failed: ");
              Serial.println(error.c_str());
              return;
            }
            for (JsonObject item : doc.as<JsonArray>()) {
              int ledIndex = item["id"]; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ...
              ledIndex -= 1;
              double h = item["h"]; // -0.6, -4.3, -2.2, -1.5, -0.5, -0.5, 0.9, -0.4, -2.5, -0.5, -2.2, -3.4, -3.9, ...
              int color = map(h, -15, 40, 170, 0);
              //it[ledIndex] = Wheel(color);
              it[ledIndex] = WheelAda(color); //Adafruit values - podivej se do wheel.h, jsou tam odkazy
              serialPrintf("okres: %d, teplota: %.2f, barva rgb: (Wheel/WheelAda) %d/%d %d/%d %d/%d\n",ledIndex,h,Wheel(color)[0],WheelAda(color)[0],Wheel(color)[1],WheelAda(color)[1],Wheel(color)[2],WheelAda(color)[2]);
            }
            //id(neo).turn_on().set_brightness(0.99).perform();
      - addressable_lambda:
          name: "Mapa teplot TMEP @tvoje___mama New Wheel"
          update_interval: 5s
          lambda: |-
            //id(getTemperaturesData).execute();
            DynamicJsonDocument doc(6144);
            Serial.println(id(tempData));
            DeserializationError error = deserializeJson(doc, id(tempData));
            if (error) {
              Serial.print("deserializeJson() failed: ");
              Serial.println(error.c_str());
              return;
            }
            for (JsonObject item : doc.as<JsonArray>()) {
              int ledIndex = item["id"]; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ...
              ledIndex -= 1;
              double h = item["h"]; // -0.6, -4.3, -2.2, -1.5, -0.5, -0.5, 0.9, -0.4, -2.5, -0.5, -2.2, -3.4, -3.9, ...
              int color = map(h, -15, 40, 170, 0);
              it[ledIndex] = Wheel(color);
              //it[ledIndex] = WheelAda(color); //Adafruit values - podivej se do wheel.h, jsou tam odkazy
              serialPrintf("okres: %d, teplota: %.2f, barva rgb: (Wheel/WheelAda) %d/%d %d/%d %d/%d\n",ledIndex,h,Wheel(color)[0],WheelAda(color)[0],Wheel(color)[1],WheelAda(color)[1],Wheel(color)[2],WheelAda(color)[2]);
            }
            //id(neo).turn_on().set_brightness(0.99).perform();
      - addressable_lambda:
          name: "TMEP @jirka1213 AdafruitWheel"
          update_interval: 5s
          lambda: |-
            //id(getTemperaturesData).execute();
            double maxTemp = -99;
            double minTemp =  99;
            DynamicJsonDocument doc(6144);
            Serial.println(id(tempData));
            DeserializationError error = deserializeJson(doc, id(tempData));
            if (error) {
              Serial.print("deserializeJson() failed: ");
              Serial.println(error.c_str());
              return;
            }
            //Zjisti min a max teplotu pro mapping
            for (JsonObject item : doc.as<JsonArray>()) {
              double h = item["h"];
              if (h < minTemp) minTemp = h;
              if (h > maxTemp) maxTemp = h;
            }

            for (JsonObject item : doc.as<JsonArray>()) {
              int ledIndex = item["id"]; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ...
              ledIndex -= 1;
              double h = item["h"]; // -0.6, -4.3, -2.2, -1.5, -0.5, -0.5, 0.9, -0.4, -2.5, -0.5, -2.2, -3.4, -3.9, ...
              int color = map(h, minTemp, maxTemp, 170, 0);
              //it[ledIndex] = Wheel(color);
              it[ledIndex] = WheelAda(color); //Adafruit values - podivej se do wheel.h, jsou tam odkazy
              serialPrintf("okres: %d, teplota: %f, barva rgb: (Wheel/WheelAda) %d/%d %d/%d %d/%d\n",ledIndex,h,Wheel(color)[0],WheelAda(color)[0],Wheel(color)[1],WheelAda(color)[1],Wheel(color)[2],WheelAda(color)[2]);
            }
            //id(neo).turn_on().set_brightness(0.99).perform();
      - addressable_lambda:
          name: "TMEP @jirka1213 New Wheel"
          update_interval: 5s
          lambda: |-
            //id(getTemperaturesData).execute();
            double maxTemp = -99;
            double minTemp =  99;
            DynamicJsonDocument doc(6144);
            Serial.println(id(tempData));
            DeserializationError error = deserializeJson(doc, id(tempData));
            if (error) {
              Serial.print("deserializeJson() failed: ");
              Serial.println(error.c_str());
              return;
            }
            //Zjisti min a max teplotu pro mapping
            for (JsonObject item : doc.as<JsonArray>()) {
              double h = item["h"];
              if (h < minTemp) minTemp = h;
              if (h > maxTemp) maxTemp = h;
            }

            for (JsonObject item : doc.as<JsonArray>()) {
              int ledIndex = item["id"]; // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, ...
              ledIndex -= 1;
              double h = item["h"]; // -0.6, -4.3, -2.2, -1.5, -0.5, -0.5, 0.9, -0.4, -2.5, -0.5, -2.2, -3.4, -3.9, ...
              int color = map(h, minTemp, maxTemp, 170, 0);
              it[ledIndex] = Wheel(color);
              //it[ledIndex] = WheelAda(color); //Adafruit values - podivej se do wheel.h, jsou tam odkazy
              serialPrintf("okres: %s, \t\tteplota: %.2f, barva rgb: (Wheel/WheelAda) %d/%d %d/%d %d/%d\n",(ledNames[ledIndex]).c_str(),h,Wheel(color)[0],WheelAda(color)[0],Wheel(color)[1],WheelAda(color)[1],Wheel(color)[2],WheelAda(color)[2]);
            }
            //id(neo).turn_on().set_brightness(0.99).perform();
      - addressable_lambda:
          name: "test kraju 1"
          update_interval: 10000ms
          lambda: |-         
            it.range(0,3) = Color::random_color(); //Karlovarsky
            it.range(3,10) = Color::random_color(); //Ustecky
            it.range(10,14) = Color::random_color(); //Liberecky
            it.range(14,19) = Color::random_color(); //KH
            it.range(19,23) = Color::random_color(); //Pardubicky
            it.range(23,32) = Color::random_color(); //Moravsloslezsky
            it.range(32,37) = Color::random_color(); //Zlinsky
            it.range(37,45) = Color::random_color(); //Jihomoravsky
            it.range(45,50) = Color::random_color(); //Vysocina
            Color olomouc = Color::random_color();
            it[23] = olomouc; //Olomoucky
            it[24] = olomouc;
            it[26] = olomouc;
            it[33] = olomouc;
            it[39] = olomouc;
            it.range(50,57) = Color::random_color();//Jihocesky
            it.range(57,64) = Color::random_color();//Plzensky
            it.range(64,76) = Color::random_color();//Stredocesky
            it[76] = Color::random_color(); //Praha
      - addressable_lambda:
          name: "test kraju 2"
          update_interval: 330ms
          lambda: |-    
            int nn = random(0,255), n[14];//from red to magenta? 255max 
            /*for (int element : n) {
              element = nn;
              nn += (220/14);
              //nn += (255/7);
              if (nn >= 220) { nn -= 220; }
              ESP_LOGD("custom", "e: %d -> %d", n, nn);
            }*/
              for (int i=0; i<14; i++) {
              n[i] = nn;
              nn += (255/15);
              //nn += (255/7);
              if (nn >= 255) { nn -= 255; }
              //ESP_LOGD("custom", "e: %d -> %d", i, n[i]);
            }  

            it.range(0,3) = Wheel(n[0]); //Karlovarsky
            it.range(3,10) = Wheel(n[1]); //Ustecky
            it.range(10,14) = Wheel(n[2]); //Liberecky
            it.range(14,19) = Wheel(n[3]); //KH
            it.range(19,23) = Wheel(n[4]); //Pardubicky
            it.range(23,32) = Wheel(n[5]); //Moravsloslezsky
            it.range(32,37) = Wheel(n[6]); //Zlinsky
            it.range(37,45) = Wheel(n[7]); //Jihomoravsky
            it.range(45,50) = Wheel(n[8]); //Vysocina
            Color olomouc = Wheel(n[9]);
            it[23] = olomouc; //Olomoucky
            it[24] = olomouc;
            it[26] = olomouc;
            it[33] = olomouc;
            it[39] = olomouc;
            it.range(50,57) = Wheel(n[10]);//Jihocesky
            it.range(57,64) = Wheel(n[11]);//Plzensky
            it.range(64,76) = Wheel(n[12]);//Stredocesky
            it[76] = Wheel(n[13]); //Praha

      # - addressable_lambda:
      #     name: "volby 1. kolo"
      #     update_interval: 65s
      #     lambda: |- 
      #       id(getVoteData1).execute();     
      #       Serial.println(id(vote1Data));   
      #       using namespace tinyxml2;
      #       XMLDocument xmlDocument;
      #       auto error = xmlDocument.Parse(id(vote1Data).c_str());
      #       Serial.println(xmlDocument.ErrorStr());
      #       if (error != XML_SUCCESS) {
      #         return;
      #       }
      #       it.range(0,3) = Color::random_color(); //Karlovarsky
      #       it.range(3,10) = Color::random_color(); //Ustecky
      #       it.range(10,14) = Color::random_color(); //Liberecky
      #       it.range(14,19) = Color::random_color(); //KH
      #       it.range(19,23) = Color::random_color(); //Pardubicky
      #       it.range(23,32) = Color::random_color(); //Moravsloslezsky
      #       it.range(32,37) = Color::random_color(); //Zlinsky
      #       it.range(37,45) = Color::random_color(); //Jihomoravsky
      #       it.range(45,50) = Color::random_color(); //Vysocina
      #       Color olomouc = Color::random_color();
      #       it[23] = olomouc; //Olomoucky
      #       it[24] = olomouc;
      #       it[26] = olomouc;
      #       it[33] = olomouc;
      #       it[39] = olomouc;
      #       it.range(50,57) = Color::random_color();//Jihocesky
      #       it.range(57,64) = Color::random_color();//Plzensky
      #       it.range(64,76) = Color::random_color();//Stredocesky
      #       it[76] = Color::random_color(); //Praha
      #       id(neo).turn_on().set_brightness(0.5).perform();
      - addressable_lambda:
          name: "5°C rozdíl na celou mapu New Wheel"
          update_interval: 50ms
          lambda: |-
            int range = 5; //kolik °c rozdílu na celou mapu
            int mint = -15; //minimální teplota, odpovídá modré barvě
            int maxt = 40; //maximální teplota, odpovídí červené barvě
            static float h = mint;
            static int direction = 1;
            // To reset static when stopping and starting the effect
            // again you can use the initial_run variables
            if (initial_run) {
              it.all() = Color::BLACK;
              h= -15;
              // optionally do a return so nothing happens until the next update_interval
              return;
            }
            // it.size() - Number of LEDs
            // it[num] - Access the LED at index num.
            // Set the LED at num to the given r, g, b values
            // it[num] = Color(r, g, b);
            // Get the color at index num (Color instance)
            // it[num].get();

            // Example: Simple color wipe
            for (int i = it.size() - 1; i > 0; i--) {
              it[i] = it[i - 1].get();
            }
            int color = map(h, mint, maxt, 170, 0); // -15 .. 40°C
            h += direction * range/float(it.size()); //
            //ESP_LOGD("custom", "h: %.2f ", h);
            if (h>=maxt & direction){
              direction = -1;
            }
            if (h<=mint & direction == -1){
              direction = 1;
            }
            it[0] = Wheel(color);

      - addressable_lambda:
          name: "5°C rozdíl na celou mapu Adafruit Wheel"
          update_interval: 50ms
          lambda: |-
            int range = 5; //kolik °c rozdílu na celou mapu
            int mint = -15; //minimální teplota, odpovídá modré barvě
            int maxt = 40; //maximální teplota, odpovídí červené barvě
            static float h = mint;
            static int direction = 1;
            // To reset static when stopping and starting the effect
            // again you can use the initial_run variables
            if (initial_run) {
              it.all() = Color::BLACK;
              h= -15;
              // optionally do a return so nothing happens until the next update_interval
              return;
            }
            // it.size() - Number of LEDs
            // it[num] - Access the LED at index num.
            // Set the LED at num to the given r, g, b values
            // it[num] = Color(r, g, b);
            // Get the color at index num (Color instance)
            // it[num].get();

            // Example: Simple color wipe
            for (int i = it.size() - 1; i > 0; i--) {
              it[i] = it[i - 1].get();
            }
            int color = map(h, mint, maxt, 170, 0); // -15 .. 40°C
            h += direction * range/float(it.size()); //
            //ESP_LOGD("custom", "h: %.2f ", h);
            if (h>=maxt & direction){
              direction = -1;
            }
            if (h<=mint & direction == -1){
              direction = 1;
            }
            it[0] = WheelAda(color);


json:

http_request:
  id: http_request_data
  useragent: esphome/rgbcrmap
  timeout: 15s

# async_tcp:

# https://arduinojson.org/v6/assistant/#/step1
time:
  - platform: sntp
    on_time:
      - seconds: 0
        minutes: /10
        then:
          - script.execute: getTemperaturesData

script:
  - id: getTemperaturesData
    mode: queued
    then:
      - logger.log:
          level: info
          format: "HTTP Request get Data"
      - http_request.get:
          url: "https://cdn.tmep.cz/app/export/okresy-cr-teplota.json"
          headers:
            Content-Type: application/json
          verify_ssl: false
          on_response:
            - if:
                condition:
                  lambda: |-
                    return status_code == 200;  
                then:
                  - logger.log:
                      level: info
                      tag: "getTemperaturedata"
                      format: "Response status: %d, Duration: %u ms"
                      args:
                        - status_code
                        - duration_ms  
                  - lambda: |- 
                      //String tempData;
                      id(tempData) = id(http_request_data).get_string();


  - id: getVoteData1
    mode: queued
    then:
      - logger.log:
          level: info
          format: "HTTP Request get Data"
      - http_request.get:
          # url: "https://www.volby.cz/pls/prez2023nss/vysledky_kraj?kolo=1&nuts=CZ041"
          # url: "https://esphome.io"
          url: "https://www.volby.cz/pls/prez2023nss/vysledky"
          headers:
            User-Agent: PostmanRuntime/7.29.2
            Accept: "*/*"
            # Accept-Encoding: gzip, deflate, br
            Connection: keep-alive
            # Content-Type: application/xml
          verify_ssl: false
          on_response:
            - if:
                condition:
                  lambda: |-
                    return status_code == 200;  
                then:
                  - logger.log:
                      level: info
                      tag: "getVoteData1"
                      format: "Response status: %d, Duration: %u ms"
                      args:
                        - status_code
                        - duration_ms  
                  - lambda: |- 
                      //String tempData;
                      id(vote1Data) = id(http_request_data).get_string();    
                      //Serial.println(id(vote1Data).c_str());            

wheel.h:

Kód: Vybrat vše

// https://votecharlie.com/blog/2018/08/improved-color-wheel-function.html
// Adapted from https://www.stm32duino.com/viewtopic.php?t=56#p8160
unsigned int sqrt32(unsigned long n) {
    unsigned int c = 0x8000;
    unsigned int g = 0x8000;
    while(true) {
    if(g*g > n) {
        g ^= c;
    }
    c >>= 1;
    if(c == 0) {
        return g;
    }
    g |= c;
    }
}

// Input values 0 to 255 to get color values that transition R->G->B. 0 and 255
// are the same color. This is based on Adafruit's Wheel() function, which used
// a linear map that resulted in brightness peaks at 0, 85 and 170. This version
// uses a quadratic map to make values approach 255 faster while leaving full
// red or green or blue untouched. For example, Wheel(42) is halfway between
// red and green. The linear function yielded (126, 129, 0), but this one yields
// (219, 221, 0). This function is based on the equation the circle centered at
// (255,0) with radius 255:  (x-255)^2 + (y-0)^2 = r^2
// Color Wheel(byte position) {  //Red & Green swapped vs Adafruit. Is this mistake?
//     byte R = 0, G = 0, B = 0;
//     if (position < 85) {
//     R = sqrt32((1530 - 9 * position) * position);
//     G = sqrt32(65025 - 9 * position * position);
//     } else if (position < 170) {
//     position -= 85;
//     R = sqrt32(65025 - 9 * position * position);
//     B = sqrt32((1530 - 9 * position) * position);
//     } else {
//     position -= 170;
//     G = sqrt32((1530 - 9 * position) * position);
//     B = sqrt32(65025 - 9 * position * position);
//     }
//     return Color(R, G, B);
// }

Color Wheel(byte position) {
    byte R = 0, G = 0, B = 0;
    if (position < 85) {
    G = sqrt32((1530 - 9 * position) * position);
    R = sqrt32(65025 - 9 * position * position);
    } else if (position < 170) {
    position -= 85;
    G = sqrt32(65025 - 9 * position * position);
    B = sqrt32((1530 - 9 * position) * position);
    } else {
    position -= 170;
    R = sqrt32((1530 - 9 * position) * position);
    B = sqrt32(65025 - 9 * position * position);
    }
    return Color(R, G, B);
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
Color WheelAda(byte WheelPos) {
    WheelPos = 255 - WheelPos;
    if(WheelPos < 85) {
        return Color(255 - WheelPos * 3, 0, WheelPos * 3);
    }
    if(WheelPos < 170) {
        WheelPos -= 85;
        return Color(0, WheelPos * 3, 255 - WheelPos * 3);
    }
    WheelPos -= 170;
    return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

//https://medium.com/@kslooi/print-formatted-data-in-arduino-serial-aaea9ca840e3
#include <stdarg.h>
#define SERIAL_PRINTF_MAX_BUFF      256
void serialPrintf(const char *fmt, ...);
void serialPrintf(const char *fmt, ...) {
    /* Buffer for storing the formatted data */
    char buff[SERIAL_PRINTF_MAX_BUFF];
    /* pointer to the variable arguments list */
    va_list pargs;
    /* Initialise pargs to point to the first optional argument */
    va_start(pargs, fmt);
    /* create the formatted data and store in buff */
    vsnprintf(buff, SERIAL_PRINTF_MAX_BUFF, fmt, pargs);
    va_end(pargs);
    Serial.print(buff);
}
okres.h:

Kód: Vybrat vše

std::string ledNums[]={
"CZ0411",
"CZ0413",
"CZ0412",
"CZ0422",
"CZ0424",
"CZ0425",
"CZ0426",
"CZ0423",
"CZ0427",
"CZ0421",
"CZ0511",
"CZ0513",
"CZ0512",
"CZ0514",
"CZ0522",
"CZ0525",
"CZ0523",
"CZ0521",
"CZ0524",
"CZ0534",
"CZ0532",
"CZ0531",
"CZ0533",
"CZ0715",
"CZ0711",
"CZ0801",
"CZ0712",
"CZ0805",
"CZ0806",
"CZ0803",
"CZ0802",
"CZ0804",
"CZ0723",
"CZ0714",
"CZ0724",
"CZ0721",
"CZ0722",
"CZ0645",
"CZ0646",
"CZ0713",
"CZ0641",
"CZ0642",
"CZ0643",
"CZ0644",
"CZ0647",
"CZ0634",
"CZ0635",
"CZ0632",
"CZ0631",
"CZ0633",
"CZ0313",
"CZ0317",
"CZ0311",
"CZ0312",
"CZ0315",
"CZ0316",
"CZ0314",
"CZ0322",
"CZ0321",
"CZ0327",
"CZ0325",
"CZ0323",
"CZ0324",
"CZ0326",
"CZ020C",
"CZ0203",
"CZ0206",
"CZ0207",
"CZ0208",
"CZ0204",
"CZ0205",
"CZ0201",
"CZ020B",
"CZ0202",
"CZ020A",
"CZ0209",
"CZ010"
};

std::string ledNames[]={
"Cheb",
"Sokolov",
"Karlovy Vary",
"Chomutov",
"Louny",
"Most",
"Teplice",
"Litoměřice",
"ÚstínadLabem",
"Děčín",
"ČeskáLípa",
"Liberec",
"Jablonec nad Nisou",
"Semily",
"Jičín",
"Trutnov",
"Náchod",
"Hradec Králové",
"Rychnov nad Kněžnou",
"Ústí nad Orlicí",
"Pardubice",
"Chrudim",
"Svitavy",
"Šumperk",
"Jeseník",
"Bruntál",
"Olomouc",
"Opava",
"Ostrava-město",
"Karviná",
"Frýdek-Místek",
"Nový Jičín",
"Vsetín",
"Přerov",
"Zlín",
"Kroměříž",
"Uherské Hradiště",
"Hodonín",
"Vyškov",
"Prostějov",
"Blansko",
"Brno-město",
"Brno-venkov",
"Břeclav",
"Znojmo",
"Třebíč",
"Žďár nad Sázavou",
"Jihlava",
"Havlíčkův Brod",
"Pelhřimov",
"Jindřichův Hradec",
"Tábor",
"České Budějovice",
"Český Krumlov",
"Prachatice",
"Strakonice",
"Písek",
"Klatovy",
"Domažlice",
"Tachov",
"Plzeň-sever",
"Plzeň-město",
"Plzeň-jih",
"Rokycany",
"Rakovník",
"Kladno",
"Mělník",
"Mladá Boleslav",
"Nymburk",
"Kolín",
"Kutná Hora",
"Benešov",
"Příbram",
"Beroun",
"Praha-západ",
"Praha-východ",
"Hlavní město Praha"
};
Vše co si přinesu domů je buď Shelly, nebo to skončí buď pod ESPhome nebo pod Zigbee2mqtt.
Ajťák co pamatuje BBS a OS/2 Warp a je mu jedno o jaký systém nebo síťařinu běží.
HA OS jako jedna z Proxmox VM na Odroid H3+/64GB https://github.com/tteck/Proxmox

kiklhorn
Moderátor
Moderátor
Příspěvky: 901
Registrován: 03. červenec 2021, 18:35
Dal poděkování: 107 poděkování
Dostal poděkování: 210 poděkování

Re: Adresovatelná mapa ČR

Příspěvek od kiklhorn »

Aktuálně mi již za pomoci Node-RED fungují prezidentské volby.
Kódy zde: https://github.com/kiklhorn/yomamamap_HA

Občas budu pokračovat, chci vylepšit UI, zatím rok a kolo zadané přímo v kódu pro ESPHome
Vše co si přinesu domů je buď Shelly, nebo to skončí buď pod ESPhome nebo pod Zigbee2mqtt.
Ajťák co pamatuje BBS a OS/2 Warp a je mu jedno o jaký systém nebo síťařinu běží.
HA OS jako jedna z Proxmox VM na Odroid H3+/64GB https://github.com/tteck/Proxmox

Odpovědět

Zpět na „ESPHome“