Your problem is similar to the one described on Github.
https://github.com/Logitech...
I had problems with my iMac for some time with the keyboard not connecting. Since resetting the keyboard everything works like a charm.
Logitech Craft Hard Reset.
1. un-pair it.
2.Press "Escape", "o", "Escape", "o", "Escape", "b".