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

[feature request] - additional token for the last part of the topic name #4

Open
ps-nl opened this issue Apr 1, 2018 · 5 comments
Open

Comments

@ps-nl
Copy link

ps-nl commented Apr 1, 2018

Would it be possible to create an additional token, that contains only the trailing part of the triggering topic?

That would make it possible to run a single wildcard flow for a sensor that spits out multiple measurements into multiple topics. For instance:
/ESP_Easy/Sensor_name/Humidity
/ESP_Easy/Sensor_name/Temperature
/ESP_Easy/Sensor_name/Pressure

If these topics are watched as "/ESP_Easy/Sensor_name/+", the "trailing part" tag would contain the measurement name, while the "message" tag contains the measured value.

I tried hacking this myself, by creating an additional token in the app.json and processing the topic string in messagehandling.js with topic.split, followed by a pop() to get the last element. But my programming skills fall short, I am afraid.

@ps-nl ps-nl changed the title [feature request] [feature request] - additional token for the last part of the topic name Apr 1, 2018
@scanno
Copy link
Owner

scanno commented Apr 1, 2018

I am not sure why you need this. The complete topic is returned (also when using + in the trigger card).
So if you register /ESP_Easy/Sensor_name/+ as topic, the current topic token will return /ESP_Easy/Sensor_name/Humidity,
/ESP_Easy/Sensor_name/Temperature or
/ESP_Easy/Sensor_name/Pressure

And what if you have multiple wildcards in a topic. A generic implementation is not that easy.

But if you want to hack yourself, you can check https://github.com/scanno/nl.scanno.mqtt/blob/beta/triggers.js#L88
there is the parsing of the topic.

You will need to add the parsing here
https://github.com/scanno/nl.scanno.mqtt/blob/beta/messagehandling.js#L24
and add the token there also

@ps-nl
Copy link
Author

ps-nl commented Apr 1, 2018 via email

@ps-nl
Copy link
Author

ps-nl commented Apr 1, 2018

I managed to make it work. If you're interested, I can create a Pull Request

Here it is: #5

@scanno
Copy link
Owner

scanno commented Apr 1, 2018

Sure, then I can take a look at it.

@scanno
Copy link
Owner

scanno commented Nov 22, 2018

Is this still actual?

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

No branches or pull requests

2 participants