richibrics / IoTuring

Your Windows, Linux, macOS computer as MQTT and HomeAssistant integration
https://pypi.org/project/IoTuring/
GNU General Public License v3.0
70 stars 6 forks source link

Support for states on EntityCommands, Monitor entity as a switch with state topic #29

Closed infeeeee closed 1 year ago

infeeeee commented 1 year ago

With this changes it's now possible to set a state for an EntityCommand, and publish it. In HomeAssistant Switches can show up as a real switch, with correct states. https://www.home-assistant.io/integrations/switch.mqtt/#state_topic

I implemented first for the Monitor entity. Unfortunately on windows you cannot get the states of the monitors, so this only works on linux, with X11. In HA for Windows machines, there is one switch now, with ON and OFF buttons, so only one line on the UI.

Tested on both Windows and Linux.

richibrics commented 1 year ago

Hi @infeeeee, Sorry for the absence, but it is the period of the exam session and I am a bit busy. I like the idea to set a value to commands. I'm not really convinced on how you implemented them: in this way we are using commands data entity as an extension of the sensors data entity, while I wanted to have them separately. PS: I also worked on a csv warehouse where sensors data can be saved but in this way I should also add switches.

What do you think if I take your solution but editing it in this way: command data entity will take an optional key of a command entity sensor, so when the value is edited to the sensor, it's sent like in your solution as state of the command.

In case you didn't understand I could be more clear. Bye

richibrics commented 1 year ago

In this way, warehouses that do not support switches/switches with value, can simply use the sensor to take the value

infeeeee commented 1 year ago

Ok, I understand what you are saying, so there should be a separate Monitor command and a Monitor sensor, and only combine them in the Homeassistant and MQTT warehouse, where it makes sense to combine them, and use the same topic as state and command. I like this approach!

I will close this and create a new PR, and cherrypick commits from here, as this requires a lot of changes, and this branch now contains a lot of unnecessary changes.

Considering #34 #35 #36:

It think they should be separate from this Monitor command, as ExternalDisplay or DisplayConfiguration or something, and they could be displayed as a Select Entity in HomeAssistant:

richibrics commented 1 year ago

Exactly (not two different entity but the sensor data and command data in the same entity, just to be sure we're on the same idea).

I totally agree to add a different entity for the configurations.

richibrics commented 1 year ago

Also the Select entity in Hass would be so nice ! Great idea

infeeeee commented 1 year ago

Exactly (not two different entity but the sensor data and command data in the same entity, just to be sure we're on the same idea).

I see now, I should use both self.RegisterEntityCommand() and self.RegisterEntitySensor() on init stage.

richibrics commented 1 year ago

Yes, but the link to the Sensor from the Command is not ready yet.