but none of them is working.
All of them are created as binary_sensor, but the first two are always off and the third (after creating a switch like this):
you can check the logs in /var/log either syslog, mosquitto.log.
Being that you can’t start the service it’s most likely a config issue in /etc/mosquitto/mosquitto.conf . Check that for anything (syslog may point to a line or systemctl status mosquitto.service will tell you what to fix).
The most likely reason for this is that the user you are running HA as does not have sudo privileges. This is a security precaution, for good reasons, and I suggest, as a beginner you do not try to circumvent it.
In any event, restarting mosquitto is not necessary, it should be run at startup and left alone
I use this sensor to check the state of the mosquitto service.
Thanks for the reply. As newbie i still do not understand how mqtt works so i am still not able to know where to read messages from mosquitto. Will you help me in understanding this so i will be able to track and fix errors by myself.
If you follow that you will see you need a client to connect to the broker to display messages. There are a number of graphical clients around, if you like those, but I find the command line client mosquitto_sub to be just as effective. Using mosquitto_pub and mosquitto_sub is described here
in a shell.
Don’t worry about publishing right now because obviously it’s not working as as. Again. Check your /etc/mosquitto/mosquitto.conf to figure out your error. The error is probably and most likely visible by checking the /var/log/syslog if you just look.
it means that there is something already using 1883, as in the service is already running or another service is using 1883.
do you see mosquitto running when you run ps -A | grep mosquitto from the shell? Ideally mosquitto should launch at boot and should never die unless it’s stopped.
The easiest thing I would recommend is a basic sensor that displays a message. Then you can use an app or HA’s MQTT client to publish messages. Once you know everything is working you can move on to other things. You’ve got to wrap your head around how topics work before it really makes sense. For instance topic-a is not the same as 'topic-a'. At least now you know its working, you just need to get some clients on and sending messages. If you use an android phone get the app ‘MQTT Dash’’’ as it can send/recv Matt messages and can make troubleshooting your HA sensors a little easier
Following some examples here i tried to make a device.tracker with mqtt to enable/disable lights when home/not_home and put this in configuration, but it seems not working as the device trackers are not created or cannot find them.
have you defined your device trackers? Are your devices publishing MQTT messages?
I’m not using the platform you are so bear with me.
A quick and dirty about MQTT…
MQTT boils down to devices and brokers. Devices are simply, devices. Imagine you have 2 bicycles, a red one and a blue one, we’ll call those devices red-bike and blue-bike. After that we have brokers. Brokers are what get messages and publish messages. They are responsible for everything. Assume your garage is your broker. It’s where you ‘place’ your client. It’s also responsible for knowing information about your client, ie whether or not your bike is in the garage determines whether or not you’re home. Now imagine when you leave you tell the garage, “I’m leaving” but you can only do this by publishing a message to a topic. Imagine Topics are the roads and routes that you take your bike on when you go out for exercise, or ride to work, or a simple neighborhood stroll. So imagine a topic is ‘red-bike/road’. So you’ve told your broker that you are taking the ‘red-bike’ on the ‘road’ but you need to deliver a message. Messages are usually placed in the syntax of topic [SPACE] message, ie red-bike/road AWAY. So, if you’re still following me and I hope you are, you’re trying to set up a platform component that reads a topic, ie red-bike/road and sets its value to the message away and that’s what is seen on HA. In order for this all to happen your device, red-bike, needs to be able to publish a message on the topic to HA in order for this all to work. It sounds confusing I’m sure but MQTT is really basic and really simple once you understand what a TOPIC and a MESSAGE is because that’s all it really is. Someone send(PUBLISHES) a message in the TOPIC to the broker and the broker tells everyone what the message is, but only those who listent (SUBSCRIBE) to that message.
I don’t manage to start mosquitto broker.
Here is what i have in mosquitto.log:
tail -f /var/log/mosquitto/mosquitto.log
1558461049: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1558462850: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1558464651: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1558466452: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1558467560: New connection from 192.168.1.96 on port 1883.
1558467560: Socket error on client , disconnecting.
1558468253: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1558470054: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1558470829: Error in poll: Interrupted system call.
1558470829: mosquitto version 1.4.10 terminating