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

MQTT fan does not work in optimistic mode #22967

Closed
raomin opened this issue Apr 10, 2019 · 13 comments · Fixed by #22976
Closed

MQTT fan does not work in optimistic mode #22967

raomin opened this issue Apr 10, 2019 · 13 comments · Fixed by #22976

Comments

@raomin
Copy link

raomin commented Apr 10, 2019

Home Assistant release with the issue:
0.91.2

Operating environment (Hass.io/Docker/Windows/etc.):
pip installed; Python 3.7.3rc1

Component/platform:
MQTT Fan

Description of problem:
MQTT fan does not work in optimistic mode. When discovered without state_topic and/or
with "optimistic":"true" the fan behaves in non-optimistic mode: setting up manually to ON and it will turn back to OFF by itself.

Steps to reproduce:

  1. With mqtt discovery configured:
mqtt:
    broker: localhost
    discovery: true
    discovery_prefix: "homeassistant"

  1. run the following command:
    mosquitto_pub -t 'homeassistant/fan/underground/config' -m '{"name":"fanUnderground","cmd_t":"homeassistant/fanUnderground/set"}'
  2. Add the fan in the UI (lovelace).
  3. Click on the switch to set it on.

2 sec later the fans turns back to off by itself.

Same behaviour when I set a state_topic and/or "optimistic":"true" in the mqtt configuration message.

@emontnemery
Copy link
Contributor

Optimistic mode is simply not implemented in MQTT Fan even though the configuration option is there, I'll fix that + add tests soon.
Out of curiousity: Why doesn't your fan send a state message back?

@github-actions
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as its been labeled with a integration (mqtt) you are listed as a codeowner for? Thanks!

@raomin
Copy link
Author

raomin commented Apr 10, 2019

Thanks for the feedbacl @emontnemery. It's also described in the documentation.
My 'fan' is actually an esp8266 controlling a powerful server fan.
I'll probably drop the 'fan' component for a number input slider to mqtt as my 'fan' can get control the power from 0-1024 and I couldn't find any MQTT component that could receive a numeric value (like a MQTT binarynumeric sensor). Maybe I'll code one...?

@emontnemery
Copy link
Contributor

I couldn't find any MQTT component that could receive a numeric value

I guess you mean you want the MQTT component to SEND a numeric value, not receive one?
If so, you could perhaps use MQTT light, with brightness support + custom icon.

@raomin
Copy link
Author

raomin commented Apr 10, 2019

Correct. I needed an HA MQTT component to SEND to my esp8266 in mqtt.
Thanks for the excellent suggestion @emontnemery I now have a nice fan ui controller :)
image

BTW the MQTT light was not optimistic until I forced it to true despite not having a state topic... Should I open a new bug?
-edit-
It appears that HASS defaults a 'state_topic': 'homeassistant/light/underground2/state' for the MQTT light although it is not part of the config mqtt message. Hence it is not optimistic because it finds a state_topic

@emontnemery
Copy link
Contributor

Yes, that's an undocumented "feature" of MQTT discovery. Are you using that?

@raomin
Copy link
Author

raomin commented Apr 11, 2019

Yes, I'm using MQTT discovery. It just that in the documentation of (all?) MQTT components, it says that

When a state topic is not available, the light will work in optimistic mode.

If MQTT forces one, then this is not true anymore.

@emontnemery
Copy link
Contributor

Yes, it's not intuitive. I opened PR #22998 to deprecate the implicit setting of state_topic. Can you verify optimistic mode works for you with that change?

@raomin
Copy link
Author

raomin commented Apr 11, 2019

Hi @emontnemery , I did test #22998 . Now the light has no implicit state_topic and operates with implicit optimism :) thanks and good job!

The fan still doesn't work on optimistic mode, so I keep the bug open for now.

@emontnemery
Copy link
Contributor

Fan optimistic mode should be fixed with #22998 (which is now merged to dev) + #22976, did you try that?

@raomin
Copy link
Author

raomin commented Apr 15, 2019

I did test #22976. The fan is not optimistic.
What I did:

  1. Get the PR: (is it enough?)
    python3 -m pip install git+https://github.com/home-assistant/home-assistant.git@refs/pull/22976/merge

  2. (restart) Version is 0.92.0.dev0

  3. Declare a mqtt fan:
    mosquitto_pub -t 'homeassistant/fan/underground4/config' -m '{"name":"fanUnderground4","cmd_t":"homeassistant/fanUnderground/set"}'

  4. Add fan.underground4 to the UI

  5. Click on the ⚡icon; a ON message is published to homeassistant/fanUnderground/set
    2 secs later, the state is back to OFF (no OFF message is published)

@emontnemery
Copy link
Contributor

emontnemery commented Apr 17, 2019

Aha, I think step 1 is not correct because it will remove #22998.

Edit: I rebased #22976 so #22998 is included, can you try again with same steps as before?

@raomin
Copy link
Author

raomin commented Apr 17, 2019

I tested again #22976 and it works. MQTT fans with no state_topic are optimistic and when declared with a state_topic, they are not. All works as expected.
Thanks @emontnemery, good job!

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

Successfully merging a pull request may close this issue.

3 participants