question

mr-23 avatar image
mr-23 asked

Shelly 1Pm MQTT Node Red

Hello, I want to control an Shelly 1PM with NodeRed with the Cerbo MQTT.

I can read all data but I can not control the ouput state of the relay.

I can see my operation in the MQTT Explorer but the state of the Shelly will not change.

If I control the operation over http everything works fine.


Attached some pictures.

1707213463556.png

The tempearture of the Add on I can read over the Mqqt.

shelly implimentation
1707213463556.png (39.0 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

9 Answers
mr-23 avatar image
mr-23 answered ·

Hello @JohnJayMack ,


here some screens:

With this I will switch on the shelly by an Battery of charge from 95% and switch of by 85%

the right string: topic_prefix/command/switch:0


1712857465597.png

1712857533359.png

1712857556108.png

1712857666647.png


1712857631085.png



1712857465597.png (23.0 KiB)
1712857533359.png (17.0 KiB)
1712857556108.png (11.2 KiB)
1712857631085.png (24.3 KiB)
1712857666647.png (15.7 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

matt1309 avatar image
matt1309 answered ·

Hi @mr-23

Can you share the commands you're using to send the request in node red?

If you search Send Command in this page it shows you how to send it using mosquitto_pub

Switch | Shelly Technical Documentation



1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

seanmoelofse avatar image seanmoelofse commented ·

Just an observation I use shellies/shelly/relay/0/command with the command on="on" and off="off"

0 Likes 0 ·
mr-23 avatar image
mr-23 answered ·

Hello Matt,

this is the test that I have set up.

1707215359043.png

1707215316433.png

1707215290215.png


1707215290215.png (26.1 KiB)
1707215316433.png (31.0 KiB)
1707215359043.png (18.7 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

matt1309 avatar image
matt1309 answered ·

Hi @mr-23

Do you have shelly 1pm or shelly1pm plus. The api documentation differs depending on that?

Shelly 1pm uses this:

Shelly1/PM: Overview – API Reference


Shelly 1pm plus: (Guessing it's this one based on name)

MQTT | Shelly Technical Documentation

Documentation has the topic in this form:

<topic_prefix>/command/switch:<id>

where <topic_prefix> is a custom prefix if set or defaults to <device_id>

I would read that as shellyplus1-<SERIAL>/command/switch:0

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

mr-23 avatar image
mr-23 answered ·

Thanks for your helb.


I have found it:

This is the right string.


topic_prefix/command/switch:0

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

johnjaymack avatar image
johnjaymack answered ·

@mr-23, have you had success controlling the shelly switch using Node Red over MQTT? could you post your commands that worked? I am sure that I am missing a small but critical command structure.

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

matt1309 avatar image matt1309 commented ·
Hi @JohnJayMack


I tihnk it depend what shelly switch you have as they have different API's/topic structures.

What device have you got?

0 Likes 0 ·
johnjaymack avatar image
johnjaymack answered ·

Hi @matt1309

shelly plus1pm. It is a single contact, 110-240 vac, 24-30 vdc.

It shows up on MQTT Explorer as

"shellies/shellyplus1pm-90380c36f9e4"

I found the following page:

Shelly1/1PM: MQTT

Shelly1 and Shelly1PM uses the following topics, where <model> is either shelly1 or shelly1pm:

  • shellies/<model>-<deviceid>/relay/0 to report status: on, off or overpower (the latter only for Shelly1PM)
  • shellies/<model>-<deviceid>/relay/0/command accepts on, off or toggle and applies accordingly
  • shellies/<model>-<deviceid>/input/0 reports the state of the SW terminal
  • shellies/<model>-<deviceid>/longpush/0 reports longpush state as 0 (shortpush) or 1 (longpush)
  • shellies/<model>-<deviceid>/input_event/0 reports input event and event counter, e.g.: {"event":"S","event_cnt":2} see /status for details

Shelly1PM adds:

  • shellies/shelly1pm-<deviceid>/relay/0/power reports instantaneous power in Watts
  • shellies/shelly1pm-<deviceid>/relay/0/energy reports an incrementing energy counter in Watt-minute
  • shellies/shelly1pm-<deviceid>/temperature reports internal device temperature in °C
  • shellies/shelly1pm-<deviceid>/temperature_f reports internal device temperature in °F
  • shellies/shelly1pm-<deviceid>/overtemperature reports 1 when device has overheated, normally 0
  • shellies/shelly1pm-<deviceid>/temperature_status reports Normal, High, Very High
  • shellies/shelly1pm-<deviceid>/relay/0/overpower_value reports the value in Watts, on which an overpower condition is detected.


1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

matt1309 avatar image matt1309 commented ·
I think that'sms the documentation for shelly pm not shelly 1 plus pm


Shelly 1pm plus documentation uses rpc where you send information via json format. For that reason I would say http endpoint is easier if you want something closer to the older style mqtt topic structure:

https://shelly-api-docs.shelly.cloud/gen2/0.14/ComponentsAndServices/Mqtt


Think you can use shellies/command to send to all which might be an option. That api documentation is the one you need though.


0 Likes 0 ·
johnjaymack avatar image
johnjaymack answered ·

Thanks for the information, @matt1309. I will investigate this path. I am not a programmer by trade, so let me ask another question.

Would I create a json file/script for the device, changing the command as necessary for the desired change, and send that json over the MQTT node?

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

matt1309 avatar image matt1309 commented ·
Yes json is a data structure.


If you aren't set on using mqtt. Http node might be easier

0 Likes 0 ·
johnjaymack avatar image
johnjaymack answered ·

Hi @matt1309 matt1309,

Thanks for the suggestion to use http. I was able to use a http request node using the Get method and with the following in the URL line: <local ip of switch>/rpc/Switch.Set?id=0&on=false <to turn off>,

<local ip of switch>/rpc/Switch.Set?id=0&on=true ,to turn on> and <local ip of switch>/rpc/Switch.Toggle?id=0 <to toggle between off and on and off etc.>.

These nodes took me a very long time to trouble shoot and I am not sure why. I entered the command directly into the address bar of my browser and it worked. I copied the command and placed it into the Node and it would not work. Finally, I did something that made a change, and I do not know what I did, and then the node began working.

Anyway, this small problem solved. I do wish that there were some working examples of the Shelly Plus 1PM being controlled by other methods, but atleast now I can continue with my original project.


Thanks again for your help.

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

matt1309 avatar image matt1309 commented ·
Glad you solved it. I agree shelly has pages of documentation on their api but it's all the useless bits in my opinion.


Id much rather gave a curl command example and maybe a python mqtt example. Everyone could guess the usage from that rather than their pages of jargon

0 Likes 0 ·

Related Resources

Additional resources still need to be added for this topic