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

feedback from tasmota #3

Closed
Zabov79 opened this issue Jan 16, 2019 · 8 comments
Closed

feedback from tasmota #3

Zabov79 opened this issue Jan 16, 2019 · 8 comments
Labels
bug Something isn't working

Comments

@Zabov79
Copy link

Zabov79 commented Jan 16, 2019

I plan to use a Sonoff/Tasmota to control my room's lights. Everything is configured and working with node red. But if I activate/deactivate the physical button on the Sonoff I don't get the status back in my Alexa app.
What do I have to put in input to the Alexa hub node and how do I have to configure it in order to update in real time the status of the Sonoff?

@datech
Copy link
Owner

datech commented Jan 16, 2019

You can do this by monitoring the MQTT messages coming from Tasmota and sending the payload back to the Amazon Echo Hub to notify it for state changes.

Example 1

The easiest way is to use "function" node in order to modify the payload.
Tasmota input

  1. Edit Amazon Echo Hub to "Enable Input"
  2. Create an input MQTT node and subscribe to Tasmota messages
  3. Create a function node to modify the payload
var nodeid="a92fedf5.1d7f4";

if (msg.payload == "on"){
    msg.payload = {
        on: true,
        nodeid: nodeid
    }

} else if(msg.payload == "off"){
    msg.payload = {
        on: false,
        nodeid: nodeid
    }
}

return msg;

nodeid variable is the ID of your Amazon Echo Device node

Example 2

Instead of Function node you can use Switch and Change nodes. Here is the example:

screenshot 2019-01-16 at 22 28 07

  1. Edit Amazon Echo Hub to "Enable Input"
  2. Create a Switch node for "on" and "off" string values
  3. Create a Change node for "off" payload. Select JSON instread of string for output
{"on":false,"nodeid":"a92fedf5.1d7f4"}
  1. Create a Change node for "on" payload. Select JSON again
{"on":true,"nodeid":"a92fedf5.1d7f4"}

Example 3

Change node can be replaced with Template node. Just select the output as "Parsed JSON"

Amazon Echo Node-Red local

@Zabov79
Copy link
Author

Zabov79 commented Jan 17, 2019

I used your first example writing the following function:

var nodeid ="24e37a31.083196";

if (msg.payload == "ON") {
    msg.payload = {
        deviceid: nodeid,
        on: true

    }

} else if(msg.payload == "OFF"){
    msg.payload = {
        deviceid: nodeid,
        on: false
        
    }
} 

return msg;

Just modified a little to avoid an error message.
Still nothing happens to my iPhone Alexa app when I manually trigger the nodes using a physical external button or manual input inn node-red. And with a vocal command to the Echo need to wait about 20 or 30 seconds to see the state changed.

@datech
Copy link
Owner

datech commented Jan 17, 2019

You have to use nodeid instead of deviceid

The Echo device will try to check the state changes by requesting in information from Amazon Echo Hub node, but you cannot specify the refresh time interval or push the state change to notify the Echo. That's why it is tacking 20-30 sec. I did tested it on my setup and on my Alexa app I see the change after 3-5 sec

@Zabov79
Copy link
Author

Zabov79 commented Jan 17, 2019

Put back as originally suggested (nodeid).
Vocal command to hub -> the device (a Sonoff/tasmota) turn on or off immediately-> after 5 to 20 seconds the state on the app change.
Manually trigger via button or node red -> the device turn off or on immediately -> nothing changes on the app. I waited up to 15 minutes with the app open...
I can't understand where I'm doing wrong...

@datech
Copy link
Owner

datech commented Jan 17, 2019

What is the topic you have subscribed for? Bases on this guide https://github.com/arendst/Sonoff-Tasmota/wiki/Commands you have to subscribe for tasmota/%my-device-name%/stat/POWER1

  • Can you debug the message coming from mqtt? Is it containing ON/OFF for payload?
  • Have you selected "Enable Input" in Amazon Echo Hub node?
  • Are you using the latest version of this npm?

PS: I've used Shelly 1 for testing it, but the principle is similar so it has to work with any MQTT controlled devices

@Zabov79
Copy link
Author

Zabov79 commented Jan 18, 2019

After having update the module to the latest possible version my flow started to loop with infinite activation or deactivation of the sonoff.
I managed to make it works using a more complex function that "stops" (i.e. send a wrong payload which is rejected from the Alexa hub node) if the same payload is injected twice.

var count=context.get('count') || 0;
var nodeid ="24e37a31.083196";

if (count===0) {
    if (msg.payload == "ON") {
        msg.payload = {
            nodeid: nodeid,
            on:true
        }
        count+=1;
    }
    else if(msg.payload == "OFF"){
        msg.payload = {
            nodeid: nodeid,
            on:false
        }
        count-=1;
    }
    context.set('count',count);
}

if (count===1 && msg.payload == "OFF") {
    msg.payload = {
            nodeid: nodeid,
            on:false
    }
    count=-1;
    context.set('count',count);
}

if (count===-1 && msg.payload == "ON") {
    msg.payload = {
        nodeid: nodeid,
        on:true
    }
    count=1;
    context.set('count',count);
}
return msg;

It may be not elegant but is the only way I found cause the Alexa hub node seems to not accept the status of a device as input.

@datech
Copy link
Owner

datech commented Jan 18, 2019

I've flashed one of my NodeMCUs with Sonoff Tasmota and I’m experience the same issue.

The issue is that Sonoff is sending POWER state MQTT messages even if the state is not changed.
For example if you send 2 cmnd/sonoff/power OFF commands. Sonoff will also send 2 MQTT messages for power state, no matter that the state is not changed as it is still OFF. This behavior is causing infinite loop.

Shelly 1 device wasn’t responding immediately with 2 MQTT messages that why this issue is not observed with Shelly.

I will try to fix it in the next version.

Thanks for find this out

@datech datech closed this as completed Jan 20, 2019
@datech datech added the bug Something isn't working label Jan 20, 2019
@datech
Copy link
Owner

datech commented Jan 20, 2019

Fixed in v0.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants