Skip to content
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

Add virtual Buttons & Switches in Digtian driver #18223

Merged
merged 2 commits into from
Mar 19, 2023

Conversation

barbudor
Copy link
Contributor

Description:

Related issue (if applicable): Followup on previous PR and the discussion with @jeroenst

Take advantage of recent support for virtual Buttons and Switches to implement that on the inputs of the DINGTIAN Relay board

3 new optional defines are supported:

#define DINGTIAN_INPUTS_INVERTED               // Invert input states (Hi => OFF, Low => ON)
#define DINGTIAN_USE_AS_BUTTON                 // Inputs as Tasmota's virtual Buttons
#define DINGTIAN_USE_AS_SWITCH                 // Inputs as Tasmota's virtual Switches
  • Only one of DINGTIAN_USE_AS_BUTTON or DINGTIAN_USE_AS_SWITCH should be used
  • DINGTIAN_INPUTS_INVERTED allows Buttons Inverted (and also invert values in Berry's tasmota.get_switches()). It also works with Switches although inversion can be handled by SwitchMode
  • All Buttons or Switches features are supported (including Rules trigger, default attachement to power and options to detach, multipress buttons, all switchmodes, ....)
  • ⚠️ Warning: On the 32 I/O version of the board, Tasmota is limited to 28 switches. Buttons can be up to 32.
  • Virtual buttons/switches are always enumerated after native GPIO. Use loglevel 3 to see which indexes are assigned to Dingtian I/O:
00:00:00.123 DNGT: clk:14, sdi:13, q7:16, pl:32, rck:15, count:8
00:00:00.124 DNGT: Dingtian relays: POWER1 to POWER8
00:00:00.125 DNGT: Dingtian inputs: Switch1 to Switch8

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.4.9
  • The code change is tested and works with Tasmota core ESP32 V.2.0.7
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@barbudor barbudor mentioned this pull request Mar 19, 2023
6 tasks
@jeroenst
Copy link
Contributor

I can confirm this works ok

@arendst arendst merged commit 948a82d into arendst:development Mar 19, 2023
@jeroenst
Copy link
Contributor

I want to thank @barbudor for this pull request.

I'm using it to control a heat pump and gas boiler by a berry script:
https://github.com/jeroenst/dingtian-heatpump-control/tree/master

arendst added a commit that referenced this pull request Mar 20, 2023
- Add support for PMSA003I Air Quality Sensor by Jean-Pierre Deschamps (#18214)
- Add support for DingTian virtual switch/button/relay (#18223)
@stefdewilde
Copy link

@jeroenst I assume you did this with the dingtian boards that weren't preprogrammed?

@jeroenst
Copy link
Contributor

jeroenst commented Mar 21, 2023

@stefdewilde I had to request a dingtian board which is unlocked and only contained test software which I erased before flashing Tasmota.

The original board/software is locked, which also makes me suspicious if any backdoors are programmed in the original code.

@barbudor barbudor deleted the digtian_inputs_as_switches branch June 9, 2023 19:04
@Maratug
Copy link

Maratug commented Aug 16, 2023

@barbudor I've compiled it with #define DINGTIAN_USE_AS_SWITCH and I've set "SetOption114 1". That didn't detached switches from their relays. Is this the expected behavior?

@barbudor
Copy link
Contributor Author

I'm unsure about the effect of SetOption114. I haven't tried it
Can you try with SwitchMode<x> 15 ?

@arendst Any reason why SO114 wouldn't work with virtual switches ?

@arendst
Copy link
Owner

arendst commented Aug 17, 2023

Just tested SO114 with PCF8574 virtual switches and it works as expected:

23:02:18.995-027 SRC: Switch
23:02:19.000-024 MQT: stat/wemos5/POWER4 = {"POWER4":"ON"}
23:02:19.005-025 MQT: stat/wemos5/POWER4 = ON
23:02:19.575-027 CFG: Saved to flash at FA, Count 733, Bytes 4096
23:02:19.683-027 SRC: Switch
23:02:19.690-024 MQT: stat/wemos5/POWER4 = {"POWER4":"OFF"}
23:02:19.695-025 MQT: stat/wemos5/POWER4 = OFF
23:02:20.611-027 CFG: Saved to flash at F9, Count 734, Bytes 4096
23:03:14.238-027 CMD: switchmode
23:03:14.240-027 SRC: Serial
23:03:14.244-027 CMD: Grp 0, Cmd 'SWITCHMODE', Idx 1, Len 0, Pld -99, Data ''
23:03:14.252-024 MQT: stat/wemos5/SWITCHMODE = {"SwitchMode1":0}
23:03:33.160-027 CMD: so114
23:03:33.162-027 SRC: Serial
23:03:33.165-027 CMD: Grp 0, Cmd 'SO', Idx 114, Len 0, Pld -99, Data ''
23:03:33.173-024 MQT: stat/wemos5/SO = {"SetOption114":"OFF"}
23:03:36.943-027 CMD: so114 1
23:03:36.945-027 SRC: Serial
23:03:36.948-027 CMD: Grp 0, Cmd 'SO', Idx 114, Len 1, Pld 1, Data '1'
23:03:36.956-024 MQT: stat/wemos5/SO = {"SetOption114":"ON"}
23:03:37.617-027 CFG: Saved to flash at F8, Count 735, Bytes 4096
23:03:40.379-024 MQT: stat/wemos5/SWITCH1 = {"Switch1":{"Action":"TOGGLE"}}
23:03:41.395-024 MQT: stat/wemos5/SWITCH1 = {"Switch1":{"Action":"TOGGLE"}}
23:03:44.394-024 MQT: stat/wemos5/SWITCH1 = {"Switch1":{"Action":"TOGGLE"}}
23:03:45.097-024 MQT: stat/wemos5/SWITCH1 = {"Switch1":{"Action":"TOGGLE"}}
23:03:47.264-024 MQT: stat/wemos5/SWITCH2 = {"Switch2":{"Action":"TOGGLE"}}
23:03:47.873-024 MQT: stat/wemos5/SWITCH2 = {"Switch2":{"Action":"TOGGLE"}}
23:03:49.503-024 MQT: stat/wemos5/SWITCH3 = {"Switch3":{"Action":"TOGGLE"}}
23:03:50.212-024 MQT: stat/wemos5/SWITCH3 = {"Switch3":{"Action":"TOGGLE"}}
23:03:51.969-024 MQT: stat/wemos5/SWITCH4 = {"Switch4":{"Action":"TOGGLE"}}
23:03:52.782-024 MQT: stat/wemos5/SWITCH4 = {"Switch4":{"Action":"TOGGLE"}}

For SO114 to work switchmode should be set between 0 and 7 and SO19 should be 0

@Maratug
Copy link

Maratug commented Aug 18, 2023

I found my problem. I had switchtopic defined and when I toggle a switch instead of "SRC: Switch" I had "SRC: MQTT" and so114 didn't work. Your log was very helpful. @arendst and @barbudor Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants