DaveMDS / node-red-contrib-tasmota

Tasmota devices for NodeRed
MIT License
23 stars 9 forks source link

Button Node configuration #30

Closed bugalaws closed 2 years ago

bugalaws commented 2 years ago

Hi Guys,

I'm using the node-red-contrib-tasmota, works great, but I can't configure a single output in a button node with a topic to distinguish the channel, ever i put the topic i get "offline" status....

Someone can help me explain how can i configure a single output with a distinguished channel by topic ?

In documentation say: "The node can be configured to send all press actions to a single output (in this case the topic is used to distinguish channels)"

DaveMDS commented 2 years ago

Hi, to use the single output mode you set in the configuration "1 Channel (or all merged)"

bugalaws commented 2 years ago

Sorry for deleted messages i will describe better below...

I my tasmota i have this setup:

image

When I click in button 1 for exemple i got this at the tasmota console:

21:26:13.431 MQT: stat/tasmota_44D83C/RESULT = {"Button1":{"Action":"SINGLE"}}

When I click in button 2 for exemple i got this at the tasmota console:

21:27:16.369 MQT: stat/tasmota_44D83C/RESULT = {"Button2":{"Action":"SINGLE"}}

At the node i have three test setups, the first one is setup with a one channel or merge:
image This way work with all channels merged, like espected for this setup.

The second one i setup with three channels: image Works fine too, each out channel represent a button, and it works fine.

So I have the thirdy scenary.. where i need only one node and get only the button 3 (single, double and hold status) i'm not know how configure correctly because i got offline status when i try especify the topic/button3 for exemple:

if i try this way: image

or this way: image

I got offline

image

Sorry i know it probably is a noob configure question, but if your can help me i'm so glad...

bugalaws commented 2 years ago

To resume the doubt is how to setup 1 channel to got the click events of a button3 for exemple....

bugalaws commented 2 years ago

0DCF7F76-AF86-4882-A661-12D460FD6500

i made this exemple what i’m thinking

for example if in channels field set 1 and put “3” in channel number the node listen only button3 events….

Ofcourse i made only a change in the html file to exemplify what i’m thinking… i don’t know if have some way to do this..

bugalaws commented 2 years ago

I don't know if have the some way most easyer than this, but i make some changes em button.html, button.js and base_tasmota.js to implement this function, now fits in my necessity 100%...

DaveMDS commented 2 years ago

If you need only button 3 events you should setup as you have done in your second image: 144498567-81541819-8950-4906-8b7b-289939253b1c

Just remove the two wires from output1 and output2 and leave only the wire connected to output3, your debug node will now receive only the events from button3

bugalaws commented 2 years ago

I don't know if you have interrest but i made some changes to i select what channel i want to listen when configured a single channel.. not is be amazing code but works .

in base_tasmota:

I add channelNumberId at const TASMOTA_DEFAULTS:

const TASMOTA_DEFAULTS = { // basic broker: '', // mandatory device: '', // mandatory name: '', outputs: 1, channelNumberId: '', uidisabler: false, // advanced fullTopic: '%prefix%/%topic%/', cmndPrefix: 'cmnd', statPrefix: 'stat', telePrefix: 'tele', qos: 1, retain: false }

in button.html i add a field below combobox of channels:

div class="form-row"> label for="node-input-outputs"> Channel Number input type="text" id="node-input-channelNumberId" placeholder="put 0(zero) to merge all channels"> /div>

and add channelNumberId: { value: 1}, in defaults of the script session:

defaults: {
  // common basic
  broker: { type: "tasmota-mqtt-broker", required: true },
  device: { value: "", required: true },
  name: { value: "" },
  outputs: { value: 1 },
  channelNumberId: { value: 1},
  uidisabler: { value: false },
  // common advanced
  fullTopic: { value: "" },
  cmndPrefix: { value: "" },
  statPrefix: { value: "" },
  telePrefix: { value: "" },
  qos: { value: 1 },
  retain: { value: false }
  // node specific
},

in button.js i change this:

  // update status icon and label
 this.setNodeStatus('green', `${action} (${channel})`)

  // build and send the new string message for topic 'buttonX'
  const msg = { topic: 'button' + channel, payload: action }
  if (this.config.outputs === 1 || this.config.outputs === '1') {
    // everything to the same (single) output
         this.send(msg)
  } else {
    // or send to the correct output
    const msgList = Array(this.config.outputs).fill(null)
    msgList[channel - 1] = msg
    this.send(msgList)
  }

to this:

  // update status icon and label
  if(parseInt(this.config.channelNumberId, 10) === 0 || parseInt(this.config.channelNumberId, 10) === channel){
    this.setNodeStatus('green', `${action} (${channel})`)
  }
  // build and send the new string message for topic 'buttonX'
  const msg = { topic: 'button' + channel, payload: action }
  if (this.config.outputs === 1 || this.config.outputs === '1') {
    // everything to the same (single) output
    if(parseInt(this.config.channelNumberId, 10) === 0 || parseInt(this.config.channelNumberId, 10) === channel){
        this.send(msg)
    }
  } else {
    // or send to the correct output
    const msgList = Array(this.config.outputs).fill(null)
    msgList[channel - 1] = msg
    this.send(msgList)
  }

Works great maybe need some improvements but already works perctly to my scenario....

bugalaws commented 2 years ago

button.zip

here is my changed files

DaveMDS commented 2 years ago

before looking at the implementation details: I really don't understand why you need those changes, I already explained how to make what you need (without changing the code), and a new config option seems to me overkill and can confuse other users.

bugalaws commented 2 years ago

For example i have a tasmota with 16 buttons and will use one node in one flow where i will use the button16 only…. I don’t like to use one node with 16outputs and use only the 16th with 15 empty output….

3FF5A23A-4AC3-4C07-B9B4-5C1FA3C352B8

I know this is a so much personal, but i think more users will like it.

By the way, sorry for any inconvenance…

DaveMDS commented 2 years ago

Ah, 16 buttons, you did non say that before, your use case start to make sense now :-)

Btw, still think the new option is a bit overkill, and then we should also implement a more complex selection, fe: someone may want to just use button 4 and 12... that start to become more complex.

In this situation I suggest to use the Button node configured as "1 Channel (or all merged)" and then attach a standard nodered "switch" node, that you can configure with a filter like: msg.topic == "button16"

bugalaws commented 2 years ago

Thanks a lot Dave, i think i'll mantain my mod for now, btw will test like you explained... And congratulations your node is amazing!!