Asystent AI
ArduinoHA, Multi St...
 
Powiadomienia
Wyczyść wszystko

ArduinoHA, Multi State Button nie wyzwala automatyzacji

1 Wpisów
1 Użytkownicy
0 Reactions
1,942 Wyświetleń
(@dawidkadziela)
Wpisów: 32
Praktykant
Autor tematu
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 
[#2641]

Cześć Wszystkim!

 

Arduino widzi się z HA. HA widzi opcje button short press i button long press, ale nie reaguje przy zwarciu pinu 9 do GND. Poniżej załączam szkic z Arduino i szkic automatyzacji.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
id: '1638427019690'
alias: Mybutton ON to OFF
description: hej
trigger:
  - platform: device
    domain: mqtt
    device_id: 0ed8d7a687af41ade0c126a651e8485d
    type: button_short_press
    subtype: mybtn
    discovery_id: 0010fa6e384a mybtn_button_short_press
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: switch.relay_1_102
        state: 'on'
action:
  - service: switch.turn_off
    target:
      entity_id: switch.relay_1_102
mode: single
#include <Ethernet.h>
#include <ArduinoHA.h>
#define MY_DEBUG
// This example uses JC Button library
//  https://github.com/JChristensen/JC_Button 
#include <JC_Button.h>

#define BUTTON_PIN      9
#define BUTTON_NAME     "mybtn"
#define BROKER_ADDR     IPAddress(192,168,0,140)
#define BROKER_USERNAME     "mqtt" // replace with your credentials
#define BROKER_PASSWORD     "1234"

byte mac[] = {0x00, 0x10, 0xFA, 0x6E, 0x38, 0x4A};

EthernetClient client;
HADevice device(mac, sizeof(mac));
HAMqtt mqtt(client, device);
HATriggers triggers;
Button btn(BUTTON_PIN);
bool holdingBtn = false;

void setup() {
  Serial.begin(9600);
    // you don't need to verify return status
    Ethernet.begin(mac);

    // set device's details (optional)
    device.setName("Arduino");
    device.setSoftwareVersion("1.0.0");

    // setup triggers
    triggers.add("button_short_press", BUTTON_NAME);
    triggers.add("button_long_press", BUTTON_NAME);
    btn.begin();

    mqtt.begin(BROKER_ADDR);
}

void loop() {
    Ethernet.maintain();
    mqtt.loop();
    btn.read();

    if (btn.pressedFor(3000) && !holdingBtn) {
        triggers.trigger("button_long_press", BUTTON_NAME);
        holdingBtn = true;
    } else if (btn.wasReleased()) {
        if (holdingBtn) {
            holdingBtn = false;
        } else {
            triggers.trigger("button_short_press", BUTTON_NAME);
        }
    }
}

 
Dodane : 03/12/2021 4:51 pm
Udostępnij: